Support Log in

33. Filter Reference

Developer Guide
Prefer video? Watch the Rank Forge tutorials 9 short guides covering every feature Watch

Some of the WordPress filters that Rank Forge hooks into, plus custom filters provided by Rank Forge for developers.

WordPress Filters Used by Rank Forge

FilterClassMethodPriorityDescription
robots_txtRANKFORGE_Robots_Txtcustom_robots_txt10Custom robots.txt content
wp_handle_upload_prefilterRANKFORGE_Image_Seoclean_upload_filename10Clean the filenames of images that a user uploads
admin_body_classRANKFORGE_Coreadd_body_class10Adds sf-admin class to admin body
pre_get_document_titleRANKFORGE_Meta_Generatorfilter_document_titlePHP_INT_MAXGives the resolved meta title to the page title of a single post on the front end
pre_get_document_titleRANKFORGE_AB_Testingfilter_document_titlePHP_INT_MAXGives the title of A/B variant B, for the post under test only
rankforge_meta_titleRANKFORGE_AB_Testingfilter_meta_titlePHP_INT_MAXGives the title of A/B variant B to <meta name="title">, og:title and twitter:title
rankforge_meta_descriptionRANKFORGE_AB_Testingfilter_meta_description10Gives the description of A/B variant B
attachment_fields_to_editRANKFORGE_Image_Seoalt_text_reminder20Missing alt text warning

Rank Forge Custom Filters

FilterParametersDescription
rankforge_resolve_meta_token$value (null), $name (string), $post_id (int)Return a string to use as the value of a {{field:NAME}} or %field:NAME% token; return $value unchanged to let Rank Forge read the field
rankforge_meta_title$title (string), $post_id (int)The title of a single post after the templates are resolved, the one value behind <title>, <meta name="title">, og:title and twitter:title (front end, single posts only); a social title typed for the post still wins for og:title and twitter:title
rankforge_meta_description$description (string)The meta description after the templates are resolved
rankforge_canonical_url$url (string), $post_id (int)The custom canonical URL stored for a post; the filter runs only for a post that has one. Return another absolute http(s) URL to use it, or an empty string for none
rankforge_sitemap_stylesheet_url$url (string)The URL of the XSL stylesheet that browsers use to show the sitemap; the default is the sitemap.xsl file in the assets folder of the plugin
rankforge_schema_render_shortcodes$render (bool, default true), $post (WP_Post)Return false to strip shortcodes instead of rendering them in the text that goes into the schema (FAQ questions and answers, HowTo and Recipe steps); called for each piece of that text that contains a shortcode
rankforge_product_brand_taxonomies$taxonomies (array, default product_brand, pwb-brand, yith_product_brand), $post_id (int)The taxonomies read, in this order, for the brand of a product in the Product schema; the earliest taxonomy in the list that has a term gives the brand
rankforge_auto_faq_schema$faq (array), $post_id (int)The FAQPage markup that Rank Forge builds by itself from a post with two or more questions when no FAQPage is printed yet (not for a post whose automatic type is Product); return an empty array to print none

Using Filters in Your Code

php
// Change the title after Rank Forge has built it
add_filter( 'rankforge_meta_title', function ( $title, $post_id ) {
    return $title . ' (' . gmdate( 'Y' ) . ')';
}, 20, 2 );

// Modify robots.txt after Rank Forge
add_filter( 'robots_txt', function ( $output, $public ) {
    $output .= "\nUser-agent: GPTBot\nDisallow: /\n";
    return $output;
}, 20, 2 );

// Image filenames are cleaned when a user uploads an image. To turn the cleaning off,
// remove its filter once Rank Forge has loaded (or set 'image_filename_cleanup' to false in the rankforge_settings option)
add_action( 'init', function () {
    if ( class_exists( 'RANKFORGE_Image_Seo' ) ) {
        remove_filter( 'wp_handle_upload_prefilter', [ RANKFORGE_Image_Seo::instance(), 'clean_upload_filename' ] );
    }
}, 20 );

// Give {{field:reading_time}} a computed value
add_filter( 'rankforge_resolve_meta_token', function ( $value, $name, $post_id ) {
    if ( 'reading_time' !== $name ) {
        return $value;
    }

    $content    = get_post_field( 'post_content', $post_id );
    $word_count = str_word_count( wp_strip_all_tags( $content ) );
    $minutes    = max( 1, (int) ceil( $word_count / 200 ) );
    return $minutes . ' min read';
}, 10, 3 );

—

Forge AI Assistant Online

Hi! I'm the Rank Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs