Custom variable in title not working

#164212
  • Resolved Blue Apple
    Rank Math free

    Hi
    I was testing out the below code which i found on your site, before adapting it for my needs:

    /**
    * Action: ‘rank_math/vars/register_extra_replacements’ – Allows adding extra variables.
    */

    add_action( ‘rank_math/vars/register_extra_replacements’, function(){
    rank_math_register_var_replacement(
    ‘ait_item_address’, //variable to add
    [
    ‘name’ => esc_html__( ‘Ait Item Address.’, ‘rank-math’ ), //variable name
    ‘description’ => esc_html__( ‘Custom variable description.’, ‘rank-math’ ), //variabledescription
    ‘variable’ => ‘ait_item_address’, //variable itself
    ‘example’ => get_ait_item_address(),
    ],
    ‘get_ait_item_address()’
    );
    });

    /* define you callback function, how and where to get the variable data*/
    function get_ait_item_address(){
    echo ‘address’;
    }

    and added to the product title using:

    %title% %sep% %customterm(product_cat)% %sep% %ait_item_address%

    It shows correctly in the backend with the word ‘address’ correctly added to product, but on the front end it’s blank showing nothing after the hyphen (%sep%).

    What could be wrong?

    Thanks
    Sam

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for contacting the support, and sorry for any inconvenience that might have been caused due to that.

    You are “echoing” your string resulting to display it in the content instead. I made some modifications to your code:

    /**
    * Action: 'rank_math/vars/register_extra_replacements' – Allows adding extra variables.
    */
    add_action( 'rank_math/vars/register_extra_replacements', function(){
    	rank_math_register_var_replacement(
    		'ait_item_address', //variable to add
    		[
    			'name' => esc_html__( 'Ait Item Address.', 'rank-math' ), //variable name
    			'description' => esc_html__( 'Custom variable description.', 'rank-math' ), //variabledescription
    			'variable' => 'ait_item_address', //variable itself
    			'example' => get_ait_item_address(),
    		],
    		'get_ait_item_address'
    	);
    });
    	
    /* define you callback function, how and where to get the variable data */
    function get_ait_item_address(){
    	return 'address';
    }

    Let me know if this code works on your end.

    We are looking forward to helping you.

    Hi,

    I have tried with return ‘address’ as well, but its not showing on the title.

    Thanks
    Sameer

    Hello,

    Thank you for the follow-up, and sorry for the delay.

    Could you please also check in the product page’s source code if the title is still showing incomplete? The filter should work after the product page loads in a browser.

    If the issue still persists, we might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress, FTP logins, and affected URL in the designated Sensitive Data section.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    Thank you, and we really look 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 3 replies - 1 through 3 (of 3 total)

The ticket ‘Custom variable in title not working’ is closed to new replies.