Dynamic meta data

#10469
  • Resolved Jason Saunders
    Rank Math free

    Recently you help me disable the plugin on a specific page and add a snippet to create page titles dynamically based on on page country filtering.

    Here’s the code:

    /**
     * Filter to change the page title.
     * 
     * @param string $title
     */
    add_filter( 'rank_math/frontend/title', function( $title ) {
    if( is_page( '1161' ) && !empty($_GET['country'])) {
        $cc = $_GET['country'];
        $countries = New WC_Countries();
        $all_countries = $countries->get_countries();
    		
        return 'Emerging sustainable designers in ' . $all_countries[$cc] . ' - Rize';
    }
    return $title;
    });
    

    What I’m wondering is whether it’s also possible to reuse the same or a tweaked version of this to also add dynamic meta descriptions too?

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

    Thank you for contacting Rank Math today.

    Yes this is possible but you would need to hook into a different filter, this filter is shown below:

    /**
     * Allow changing the meta description sentence from within the theme.
     *
     * @param string $description The description sentence.
     */
    add_filter( 'rank_math/frontend/description', function( $description ) {
    	return $description;
    });

    Let me know if you have additional questions.

    Thank you.

    ​​​​​​

    Awesome. Thanks again 🙂

    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 3 replies - 1 through 3 (of 3 total)

The ticket ‘Dynamic meta data’ is closed to new replies.