How i can get the on post title using php

#211119
  • Resolved Wasiq
    Rank Math free

    HI

    i am working on the api which will generate dynamic seo meta i wonder if you have a function where i can get the post meta using post it. i already try this

    RankMath\Paper\Paper::get()->get_title()

    but i cant get anything as its not against a post

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

    Thanks for contacting us. Sorry for the delay and any inconvenience that might have been caused due to that.

    Can you please confirm if you want to use your post’s title as SEO Title and Description?

    If yes then you can simply set this in the Global Settings. Please navigate to WP Dashboard > Rank Math > Titles & Meta > Posts and use %title% in the Single Post Title and Single Post Description field:

    Hope this helps. Let us know if you are trying to achieve something else or need any further assistance.

    Wasiq
    Rank Math free

    Thanks for your reply but thia not what i want. I need to get post meta title using post id. As in your examples its just shows for updating not fetching against post. Like i said i am making api so need to get post meta title using post id

    Ankit
    Rank Math business

    Hello,

    Thank you for your reply.

    That feature is unfortunately not available at the moment. We don’t support fetching the data via the Rest API or GraphQL at the moment.

    With that being said, there are existing feature requests, so I’ve added your vote to our internal suggestions lists. If your suggestions are something that we’re able to introduce, I’ll be sure to let you know.

    Don’t hesitate to get in touch if you have any other questions.

    Wasiq
    Rank Math free

    Thanks but is there any way i can fetch post meta title using post id

    Brian
    Rank Math free

    Hello,

    Thank you for getting back to us.

    Could you please try creating a title function and use the RankMath\Post::get_meta( 'title', $post->ID ) method to call it.

    Here is a sample code to which you can use. Please note that the code below is not tested for functionality purposes.

    add_filter( 'rank_math/frontend/title', function( $title ) {
    if ( is_single() ) {
        global $post;
    
        $title = RankMath\Post::get_meta( 'title', $post->ID );
            if ( '' !== $title ) {
                return $title;
            }
    }}

    Hope this helps. Please let us know if you need any other assistance.

    Wasiq
    Rank Math free

    Thanks that only helps if title tag is added manually but if it is generated on fly which function should i have to use

    Brian
    Rank Math free

    Hello,

    Thank you for getting back to us,

    There are usually two ways in which you can fetch the title. Either pull it from the database of fetch itdynamically. The dynamic processing feature is great because it allows the content to be maintained once and used severally.

    Stored in Database: <p><?php echo get_post_meta($post->ID, 'rank_math_title', true); ?></p>
    Dynamic Processing: <p><?php echo RankMath\Post::get_meta( 'title', $post->ID ); ?></p>

    The dynamic processing code sample came from this existing RankMath description code as you can see here:
    https://rankmath.com/kb/filters-hooks-api-developer/#use-global-meta-description

    Hope this helps.
    Thank you.

    Wasiq
    Rank Math free

    Thanks alot that helps you can close the ticket

    Hello,

    Glad that helped.

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

    We are here to help.

    Thank you.

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

The ticket ‘How i can get the on post title using php’ is closed to new replies.