edit title for a specific page in a function ?

#17427
  • Resolved Gregory
    Rank Math free

    Hello,

    i use a professionnal template that register a custom post type.
    the theme add a page that list all those custom posts.
    but this page is not a normal wordpress page, so i have no option to manage title settings.
    is there a way to handle this, like adding a function in functions.php ?

    thanks a lot for your help.

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

    Thank you for contacting Rank Math today.

    For such a setup, you would need to modify the actual page/template file that is used to show the page. From within this file.

    You can use this code to get the global meta description and set it to a global variable.

    
    
    add_action( 'rank_math/frontend/description', function( $description ) {
     global $post;
     global $rm_meta_desc = RankMath\Post::get_meta( 'description', $post->ID );
    
     return $description;
    });

    Looking forward to helping you. Thank you.

    ​​​​​​

    ok,

    after investigating,
    this page has no ID.
    it’s a static page with archive-cpt.php structure in template.

    it get the get_header(); hook,
    so can i modify it seo settings by there ?

    ps : it’s title i want to update, but thanks for the meta description info !

    • This reply was modified 4 years, 6 months ago by Gregory.

    Hello,

    Thank you for contacting Rank Math today.

    You can make use of the following filter to set a static title for the archive page. You would first need to add some logic to check the current page and map the custom title:

    /**
     * Filter to change the page title.
     * 
     * @param string $title
     */
    add_filter( 'rank_math/frontend/title', function( $title ) {
            if($_SERVER['REQUEST_URI'] =="/page_name/"){
                 $title = "Custom meta title here";
                 return $title;
            }
    	return $title;
    });

    Looking forward to helping you. Thank you.

    ​​​​​​

    thanks, it works well

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/?rate=5#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do 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 5 replies - 1 through 5 (of 5 total)

The ticket ‘edit title for a specific page in a function ?’ is closed to new replies.