Use rank math’s placeholders like %sitename% and %title% inside blog content

#868345
  • Resolved Edopedia
    Rank Math free

    Hi, I want to use your placeholder variables in my posts and pages content. Currently, it only works in meta titles. However, I also want to use them inside the actual h1 and body.

    I asked chatgpt about this and the answer it gave me is not working. I want the ability to access all variables if possible.

    Please help me. Thanks.

    ===========================

    Below was the answer from chatgpt:

    Rank Math’s placeholders, like %sitename% and %title%, are typically used for SEO metadata, such as in title tags and meta descriptions, rather than directly within blog post content. However, if you want to use these placeholders within the content of your WordPress blog posts, you can follow these steps:

    Method 1: Use a Plugin
    Install a Shortcode Plugin: Use a plugin that allows you to create custom shortcodes in WordPress. For example, plugins like “Shortcoder” or “Custom Content by Country (C3)” can help.

    Create Custom Shortcodes:

    Go to the plugin settings and create a new shortcode.
    Define the shortcode to output the desired Rank Math placeholder value.
    Use the shortcode in your blog post content.

    Method 2: Use Custom Code
    If you’re comfortable with PHP and editing your theme’s functions.php file, you can create a custom shortcode to process the Rank Math placeholders.

    Add a Custom Function:

    Go to Appearance > Theme Editor in your WordPress dashboard.
    Open the functions.php file of your active theme.
    Add the following code:

    function rank_math_placeholder_shortcode( $atts ) {
    $atts = shortcode_atts( array(
    ‘placeholder’ => ”,
    ), $atts, ‘rank_math_placeholder’ );

    if ( function_exists( ‘rank_math_replace_variables’ ) ) {
    return rank_math_replace_variables( $atts[‘placeholder’] );
    }

    return ”;
    }
    add_shortcode( ‘rank_math’, ‘rank_math_placeholder_shortcode’ );

    Use the Shortcode in Posts:

    Use the shortcode in your post content like this:

    [rank_math placeholder=”%sitename%”]
    [rank_math placeholder=”%title%”]

    This will replace the placeholders with their respective values.

Viewing 1 replies (of 1 total)
  • Hello,

    Those variables can only work in our plugin’s fields. However, those details are already added to the metadata of your pages/posts and the search engines can read them from there.

    Adding them to your content will not have any actual SEO benefits.

    If you still want to add the other variables to shortcode, you can use a plugin like this instead:
    https://wordpress.org/plugins/shortcoder/

    However, here’s a filter you can use and customize to register Rank Math variables into shortcodes:

    add_shortcode('title', function() {
    	$title = get_the_title();
    	return $title;
    });
    
    add_shortcode('sitename', function() {
    	$sitename = RankMath\Helper::replace_vars("%sitename%");
    	return $sitename;
    });

    Once done, you can use [title] and [sitename] shortcode on your content.

    Looking forward to helping you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 1 replies (of 1 total)

The ticket ‘Use rank math’s placeholders like %sitename% and %title% inside blog content’ is closed to new replies.