Support Log in

13. Custom Field Tokens in Meta Templates

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

Rank Forge has one hook for custom values in meta templates: the rankforge_resolve_meta_token filter. It runs for each {{field:NAME}} or %field:NAME% token in a template. Rank Forge has no hook that adds a new {{name}} variable to the template editor.

Giving a value to a field token

The filter gets null, the name of the field and the post ID. Return a string and Rank Forge uses it as the value. Return $value unchanged and Rank Forge reads the field itself.

php
// Answer {{field:price}} (or %field:price%) with the WooCommerce price of the product
add_filter( 'rankforge_resolve_meta_token', function ( $value, $name, $post_id ) {
    if ( 'price' !== $name || ! function_exists( 'wc_get_product' ) ) {
        return $value;
    }

    $product = wc_get_product( $post_id );
    if ( ! $product || ! $product->get_price() ) {
        return '';
    }

    // wc_price() returns HTML with entities; the meta tags need plain text
    return html_entity_decode( wp_strip_all_tags( wc_price( $product->get_price() ) ), ENT_QUOTES, 'UTF-8' );
}, 10, 3 );

Using the token in a template

Put the token in the Title Template or the Description Template of a post type, in Rank Forge > Settings, tab Search Appearance:

text
{{title}} {{separator}} {{field:price}} {{separator}} {{siteName}}

Custom fields without the filter

A {{field:NAME}} token needs no code for a custom field. Rank Forge asks the filter, then get_field() when ACF or the FieldForge ACF compatibility layer is loaded, then the post meta with that key. An array or an object is written as JSON. A field that is empty or missing gives an empty string, and the cleanup removes a separator left dangling.

—

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