Custom field in page title for product categories

#377380
Viewing 12 replies - 1 through 12 (of 12 total)
  • Nigel
    Rank Math business

    Hello,

    Thank you for contacting Rank Math for help with custom fields for WooCommerce category pages

    Rank Math only supports custom fields for single post pages. To Use a custom field on a category page, you’ll need to create a custom variable callback. Please refer to the following guide for how to do that: https://rankmath.com/kb/filters-hooks-api-developer/#add-extra-variables

    Hope that helps. Please let us know if you have questions.

    If I change for testing:

    function alt_title_callback(){	
    	
    	return "test";
    }

    This works perfectly, no idea what’s wrong.

    Thank you, I have created this function:

    add_action( 'rank_math/vars/register_extra_replacements', function(){
    	rank_math_register_var_replacement(
    		'alt_title',
    		[
    		'name'        => esc_html__( 'Alternative title', 'rank-math' ),
    		'description' => esc_html__( 'Alternative title for categories', 'rank-math' ),
    		'variable'    => 'alt_title',
    		'example'     => 'alt_title_callback()',
    		],
    		'alt_title_callback'
    		);
    	   });
    function alt_title_callback(){	
    	$alt_title = the_field('alt_title', 'term_'.get_queried_object()->term_id);
    	
    	return $alt_title;
    }

    But the alt_title appear to the top of the page instead of <title> tag:

    https://prnt.sc/FSi32jNvK-nM
    https://prnt.sc/5SGXTQa9Xmwe

    Hello,

    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 in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.
    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/

    We really look forward to helping you.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Hello,

    I tried accessing your admin dashboard but your website seems to be currently blocking us. Please check the screenshot image I shared in the Sensitive Data section.

    If you are using a geo-blocking, please temporarily unblock the country Portugal, India and the Philippines so we can further investigate the issue.

    Looking forward to helping you on this one.

    Hi Jeremy,

    sorry, please try again now.

    Thanks, Petr

    Hello,

    I am now able to access your admin dashboard. Thank you so much.

    I tried modifying the code in your admin dashboard but it seems that the theme editor keeps on changing its format.

    We would like to conduct further troubleshooting, can you please provide your FTP login as well?

    Looking forward to helping you on this one.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Nigel
    Rank Math business

    Hello,

    Thank you for your patience as we look into why the meta title was appearing at the top of your pages.

    in the alt_title_callback function you create I replace the_field function with get_field. the_field has an echo which gives output whenever the callback function runs.

    Hope that helps. please let us know if you have questions.

    Oh, that’s the problem! Very well, thank you so much!

    Petr

    Hello,

    We are super happy that this resolved your issue.

    If you have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 12 replies - 1 through 12 (of 12 total)

You must be logged in to reply to this ticket.