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 / hide-the-primary-category-dropdown-on-the-post-edit-screen.php
Created October 23, 2026 12:47
Hide the primary category dropdown on the post edit screen
<?php
// Hide the dropdown everywhere.
add_filter( 'seopress_primary_term_inline_selector', '__return_false' );
// Hide it in the Categories box only.
add_filter( 'seopress_primary_term_inline_selector', 'sp_hide_primary_category_dropdown', 10, 3 );
function sp_hide_primary_category_dropdown( $enabled, $taxonomy, $post_type ) {
if ( 'category' === $taxonomy ) {
return false;
}
@wp-seopress
wp-seopress / choose-the-custom-fields-read-for-internal-linking-suggestions.php
Created October 21, 2026 09:19
Choose the custom fields read for internal linking suggestions
<?php
// Meta keys read in addition to post_content (default: the ACF fields of the post).
function sp_significant_kw_custom_fields( $keys, $post ) {
$keys[] = 'my_builder_text';
return $keys;
}
add_filter( 'seopress_pro_significant_kw_custom_fields', 'sp_significant_kw_custom_fields', 10, 2 );
// ACF field types considered page text (default: text, textarea, wysiwyg).
@wp-seopress
wp-seopress / filter-the-ai-generated-caption-and-description-before-saving.php
Created October 21, 2026 09:15
Filter the AI generated caption and description before saving
<?php
// Caption (saved as post excerpt), already sanitized with sanitize_text_field().
function sp_update_caption( $caption, $post_id ) {
return $caption;
}
add_filter( 'seopress_update_caption', 'sp_update_caption', 10, 2 );
// Description (saved as post content), already sanitized with wp_kses_post().
function sp_update_description( $description, $post_id ) {
return $description;
@wp-seopress
wp-seopress / filter-the-ai-generated-alt-text-before-saving.php
Created October 21, 2026 09:11
Filter the AI generated alt text before saving
<?php
function sp_update_alt( $alt_text, $post_id ) {
return trim( $alt_text, ". \t\n" );
}
add_filter( 'seopress_update_alt', 'sp_update_alt', 10, 2 );
@wp-seopress
wp-seopress / filter-post-types-and-posts-listed-in-llms-txt.php
Created October 21, 2026 09:07
Filter post types and posts listed in llms.txt
<?php
/**
* Remove a post type from llms.txt.
*
* By default: public post types except attachment, seopress_404, seopress_schemas, seopress_bot.
*
* @param string[] $types Post type names.
*
* @return string[]
*/
@wp-seopress
wp-seopress / filter-the-prompt-sent-to-ai-to-generate-image-metadata.php
Created October 21, 2026 09:00
Filter the prompt sent to AI to generate image metadata
<?php
// Replace {provider} in the hook name, e.g. seopress_ai_openai_image_meta.
function sp_ai_image_meta_prompt( $prompt, $post_id ) {
// $prompt lists the requested fields (alt_text, caption, description).
return $prompt . "\nMention the brand name when relevant.";
}
add_filter( 'seopress_ai_openai_image_meta', 'sp_ai_image_meta_prompt', 10, 2 );
@wp-seopress
wp-seopress / filter-the-custom-instructions-sent-to-ai.php
Created October 21, 2026 08:53
Filter the custom instructions sent to AI
<?php
// Replace {provider} in the hook name, e.g. seopress_ai_openai_custom_instructions.
function sp_ai_custom_instructions( $instructions, $post_id ) {
// $instructions: the site-wide custom instructions from the settings.
// $post_id: 0 for taxonomy terms.
return $instructions . ' Always write in a friendly tone.';
}
add_filter( 'seopress_ai_openai_custom_instructions', 'sp_ai_custom_instructions', 10, 2 );
@wp-seopress
wp-seopress / filter-the-content-analysed-for-internal-linking-suggestions.php
Created October 21, 2026 08:44
Filter the content analysed for internal linking suggestions
<?php
// Decide whether blocks and shortcodes are rendered before extraction.
function sp_significant_kw_render_content( $should_render, $post ) {
return $should_render;
}
add_filter( 'seopress_pro_significant_kw_render_content', 'sp_significant_kw_render_content', 10, 2 );
// Provide the text yourself, e.g. for a builder that renders outside WordPress.
function sp_significant_kw_content( $content, $post, $raw ) {
$builder_text = get_post_meta( $post->ID, 'my_builder_text', true );
@wp-seopress
wp-seopress / filter-llms-txt-content-and-url.php
Created October 21, 2026 08:32
Filter llms.txt content and URL
<?php
/**
* Append a line to the generated llms.txt file.
*
* @param string $content The final llms.txt content.
*
* @return string
*/
function sp_llms_txt_file( $content ) {
return $content . "\n> Contact: https://example.com/contact/\n";
@wp-seopress
wp-seopress / filter-the-merchantreturnpolicy-schema.php
Created October 21, 2026 08:28
Filter the MerchantReturnPolicy schema
<?php
/**
* Filter the MerchantReturnPolicy schema built from the WooCommerce return policy settings.
*
* @param array $policy The policy schema (@type, applicableCountry, returnPolicyCategory...).
* @param array $options The seopress_pro_option_name option.
*
* @return array
*/
function sp_merchant_return_policy( $policy, $options ) {