Uppercase in meta title

#568951
  • Resolved Dre
    Rank Math free

    Hi,
    I would like some parts of the meta title to be in uppercase letters. Here is what I need:

    %customfield(my_field)% %title% %sep% %sitename%

    The customfield should be uppercase letters. How can I achieve this?

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

    Thank you for your query and we are so sorry about the trouble this must have caused.

    This would require you to create a custom variable that retrieves the said field and convert it to uppercase.

    To do so, you may refer to this custom code I made:

    add_action( 'rank_math/vars/register_extra_replacements', function(){
    	rank_math_register_var_replacement(
    	   'shortcode_var_name', [
    	   'name'        => esc_html__( 'Author name', 'rank-math' ),
    	   'description' => esc_html__( 'Author description', 'rank-math' ),
    	   'variable'    => 'shortcode_var_name', /* the actual variable: %shortcode_var_name% */
    	   'example'     => shortcode_var_name_call_back(),
    	   ],
    	   'shortcode_var_name_call_back'
       );
    });
    function shortcode_var_name_call_back(){
    	global $post;
    	return strtoupper(get_field('my_field', $post->ID));
    }

    You need to replace the my_field with your preferred field name.

    After that, you can use the shortcode %shortcode_var_name% instead. Of course, you can freely change the variable name to anything you want.

    You may refer to this guide on how to add the code to your website: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Hope that helps and please do not hesitate to let us know if you need my assistance with anything else.

    Dre
    Rank Math free

    Hi,
    there must be an error in youur code – I am getting a critical error when I add the snippet to my child theme’s funnctions…

    Hello,

    Sorry for the error on your site.

    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/

    Looking forward to helping you.

    Thank you.

    Dre
    Rank Math free

    Hello,

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

    Thank you.

    Dre
    Rank Math free

    Hi, please see the data I added.

    Hello,

    Thanks for your patience.

    It seems you didn’t have the Advanced Custom Fields plugin installed on your site and which is why the code was not being added and throwing an error.

    Also, you didn’t apply the variable %shortcode_var_name% in your title, thus it wasn’t updating.

    I’ve installed the plugin and changed the variable to %shortcode_var_name%. Now it’s working perfectly fine on your site.

    Please refer to the screenshot attached in the sensitive data section.

    Hope that helps, and please do not hesitate to let us know if you need our assistance with anything else.

    Thank you.

    Dre
    Rank Math free

    Hi,
    no, I don’t want to use a plugin!
    I have added the custom field without the ACF plugin, simply by adding it to each product with the native WP meta fields, so please let me know how to achieve my goal with this, not with ACF plugin.

    Thanks.

    Hello,

    I’ve modified the code a bit for you and now it’s working without the ACF plugin:

    add_action( 'rank_math/vars/register_extra_replacements', function(){
    	rank_math_register_var_replacement(
    	   'shortcode_var_name', [
    	   'name'        => esc_html__( 'Author name', 'rank-math' ),
    	   'description' => esc_html__( 'Author description', 'rank-math' ),
    	   'variable'    => 'shortcode_var_name', /* the actual variable: %shortcode_var_name% */
    	   'example'     => shortcode_var_name_call_back(),
    	   ],
    	   'shortcode_var_name_call_back'
       );
    });
    function shortcode_var_name_call_back(){
    	global $post;
    	return strtoupper(get_post_meta($post->ID, 'my_field', true));
    }

    Hope that helps, and please do not hesitate to let us know if you need our assistance with anything else.

    Thank you.

    Dre
    Rank Math free

    Thank you very much!

    Hello,

    We’re glad that this resolved your issue.

    Please feel free to reach out to us again in case you need any other assistance.

    We are here to help.

    Thank you.

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

The ticket ‘Uppercase in meta title’ is closed to new replies.