Skip to content

Instantly share code, notes, and snippets.

View wp-seopress's full-sized avatar
😊
Coding SEOPress, best WordPress SEO plugin

Benjamin Denis wp-seopress

😊
Coding SEOPress, best WordPress SEO plugin
View GitHub Profile
@wp-seopress
wp-seopress / filter-the-generated-video-sitemap-content-of-a-post.php
Created June 16, 2026 13:34
Filter the generated video sitemap content of a post
add_filter( 'seopress_pro_video_sitemap_builder_content', 'sp_pro_video_sitemap_builder_content', 10, 2 );
function sp_pro_video_sitemap_builder_content( $buffer, $post_id ) {
// Adjust the <video:video> entries generated for this post.
return $buffer;
};
@wp-seopress
wp-seopress / filter-the-http-request-arguments-sent-by-the-ai-assistant.php
Created June 16, 2026 13:29
Filter the HTTP request arguments sent by the AI Assistant
add_filter( 'seopress_ai_assistant_request_args', 'sp_ai_assistant_request_args', 10, 2 );
function sp_ai_assistant_request_args( $args, $provider ) {
// Increase the timeout for AI Assistant requests.
$args['timeout'] = 60;
return $args;
};
@wp-seopress
wp-seopress / filter-the-inline-css-of-the-google-preferred-sources-button.php
Created June 16, 2026 13:24
Filter the inline CSS of the Google Preferred Sources button
add_filter( 'seopress_preferred_source_inline_css', 'sp_preferred_source_inline_css', 10, 1 );
function sp_preferred_source_inline_css( $css ) {
// Remove the default inline CSS and style the button from your theme.
return '';
};
@wp-seopress
wp-seopress / filter-the-html-of-the-google-preferred-sources-button.php
Created June 16, 2026 13:18
Filter the HTML of the Google Preferred Sources button
add_filter( 'seopress_preferred_source_html', 'sp_preferred_source_html', 10, 4 );
function sp_preferred_source_html( $button, $args, $domain, $url ) {
// Wrap the button in a custom container.
return '<div class="my-preferred-source">' . $button . '</div>';
};
@wp-seopress
wp-seopress / filter-the-http-request-arguments-used-by-the-xml-sitemap-health-check.php
Created June 16, 2026 13:14
Filter the HTTP request arguments used by the XML sitemap health check
add_filter( 'seopress_sitemap_diagnostic_request_args', 'sp_sitemap_diagnostic_request_args', 10, 2 );
function sp_sitemap_diagnostic_request_args( $args, $url ) {
// Give the health check more time on slow servers.
$args['timeout'] = 30;
return $args;
};
@wp-seopress
wp-seopress / filter-whether-seopress-abilities-are-exposed-over-the-rest-api.php
Created June 16, 2026 13:09
Filter whether SEOPress abilities are exposed over the REST API
add_filter( 'seopress_abilities_api_rest_enabled', 'sp_abilities_api_rest_enabled', 10, 1 );
function sp_abilities_api_rest_enabled( $enabled ) {
// Expose the SEOPress abilities over REST only on staging.
if ( 'staging' === wp_get_environment_type() ) {
return true;
}
return $enabled;
};
@wp-seopress
wp-seopress / filter-the-post-types-used-to-generate-the-markdown-version.php
Last active June 1, 2026 12:19
Filter the post types used to generate the Markdown version
add_filter( 'seopress_agent_ready_markdown_post_types', 'sp_agent_ready_markdown_post_types', 10, 1 );
function sp_agent_ready_markdown_post_types( $types ) {
$types[] = 'your_cpt_key';
$types[] = 'your_cpt_key_2';
return $types;
};
@wp-seopress
wp-seopress / always-send-the-parent-product-id-to-google-analytics-4.php
Created May 22, 2026 13:40
Always send the parent product ID to Google Analytics 4
<?php
/**
* SEOPress PRO — Always send the parent product ID to Google Analytics 4.
*
* By default SEOPress sends the variation SKU (or, as fallback, the variation ID)
* for each line item in a WooCommerce order. Some shops prefer to aggregate
* analytics at the parent product level — e.g. a single "Blue T-Shirt" row in GA4
* instead of one row per size / color variation. This snippet returns the SKU
* (or ID) of the parent product whenever a variation is purchased.
*
@wp-seopress
wp-seopress / last-resort-post-id-resolver-for-search-console-rows-via-polylang.php
Last active May 22, 2026 13:34
Last-resort post ID resolver for Search Console rows via Polylang
<?php
/**
* SEOPress PRO — Last-resort post ID resolver for Search Console rows via Polylang.
*
* When url_to_postid() returns 0 (typically because the URL belongs to a translation
* whose permalink is owned by the multilingual plugin), this snippet asks Polylang
* to resolve the URL using its own router. The resolved post then receives the
* GSC metrics (clicks, impressions, CTR, position) on each daily sync.
*
* Hook: seopress_search_console_match_post_id
@wp-seopress
wp-seopress / strip-the-language-prefix-from-search-console-urls-before-matching.php
Created May 22, 2026 13:26
Strip the language prefix from Search Console URLs before matching
<?php
/**
* SEOPress PRO — Strip the language prefix from Search Console URLs before matching.
*
* Multilingual plugins (Polylang, WPML, TranslatePress…) prepend a language segment
* (e.g. /en/, /fr/) to public URLs but do not register that segment in WP_Rewrite.
* As a result, url_to_postid() cannot match the raw URL returned by Google Search
* Console. This snippet removes a known list of language prefixes so SEOPress can
* resolve the WordPress post and store GSC impressions / clicks / CTR / position
* against it.