add custom title and meta to a page template

#615991
  • Resolved Anonymous
    Rank Math free

    I have a custom page template built in PHP, so there is not rankmath settings i can edit for this page.
    There is not post type it’s a post type archive.

    I’m trying to write a custom title and meta description in the template with the following code but it’s not working.

    get_header();

    $queried_object = get_queried_object();
    $post_type = get_taxonomy( $queried_object->taxonomy )->object_type[0];

    // Set custom title and meta description for SEO
    if ( function_exists( 'rank_math' ) ) {
    $page_title = 'Insurance Marketplace: Buy Insurance Online at the Lowest Prices';
    $meta_description = 'Navigate the insurance marketplace and buy insurance online now. Enjoy the convenience of finding the lowest prices tailored for your needs.';

    rank_math()->titles->title = $page_title;
    rank_math()->titles->description = $meta_description;
    }
    ?>

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

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

    Please refer to these filter code to change the meta title or description of your custom page:

    add_filter('rank_math/frontend/title', function ($title) {
    	return $title;
    });
    add_filter('rank_math/frontend/description', function ($description) {
    	return $description;
    });

    Since you have initialized the get_header, the code should work.

    Let us know how that goes. Looking forward to helping you.

    Anonymous
    Rank Math free

    Thanks I added that code to my functions.php file but I’m not seeing the change on the frontend.

    Hello,

    Please note that the code I shared previously is just a placeholder. You would still need to modify that to meet your goal. Can you please confirm if you have done so? If you did and the issue 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 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,

    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 ‘add custom title and meta to a page template’ is closed to new replies.