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
| Filter | Class | Method | Priority | Description |
|---|---|---|---|---|
robots_txt | RANKFORGE_Robots_Txt | custom_robots_txt | 10 | Custom robots.txt content |
wp_handle_upload_prefilter | RANKFORGE_Image_Seo | clean_upload_filename | 10 | Clean the filenames of images that a user uploads |
admin_body_class | RANKFORGE_Core | add_body_class | 10 | Adds sf-admin class to admin body |
pre_get_document_title | RANKFORGE_Meta_Generator | filter_document_title | PHP_INT_MAX | Gives the resolved meta title to the page title of a single post on the front end |
pre_get_document_title | RANKFORGE_AB_Testing | filter_document_title | PHP_INT_MAX | Gives the title of A/B variant B, for the post under test only |
rankforge_meta_title | RANKFORGE_AB_Testing | filter_meta_title | PHP_INT_MAX | Gives the title of A/B variant B to <meta name="title">, og:title and twitter:title |
rankforge_meta_description | RANKFORGE_AB_Testing | filter_meta_description | 10 | Gives the description of A/B variant B |
attachment_fields_to_edit | RANKFORGE_Image_Seo | alt_text_reminder | 20 | Missing alt text warning |
Rank Forge Custom Filters
| Filter | Parameters | Description |
|---|---|---|
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 );—