How to add Description for Search Results

#661106
Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    Unfortunately, there is no option available in Rank Math to set the meta description for your Search Pages as it is recommended to set those pages noindex because they are usually not heavy on content and they can create duplicate content issues.

    However, if you want you can use the following filter to add a custom meta description for all of your search pages:

    add_filter( 'rank_math/frontend/description', function( $description ) {
        $url = home_url( $_SERVER['REQUEST_URI'] );
        if (strpos($url,'?s=') !== false ){
            $description = 'custom description';
        };
    
        return $description;
    });
    

    Here’s how you can add filter/hook to your WordPress site:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Hope that helps and please don’t hesitate to let us know if you have any other questions.

    Thank you.

    ​​​​​​​

    Roni Syah
    Rank Math free

    how to show %search_query% in description https://imgur.com/7Nq47Hg

    Sample : Watch %search_query%, hd porn videos for free on PornhubXvideos, Find the most relevant collection of porn videos and Sex Movies in Full HD high quality.

    results : Watch Bokep Indo, hd porn videos for free on PornhubXvideos, Find the most relevant collection of porn videos and Sex Movies in Full HD high quality.

    plesae give me code

    Roni Syah
    Rank Math free

    add_filter( ‘rank_math/frontend/description’, function( $description ) {
    $url = home_url( $_SERVER[‘REQUEST_URI’] );
    if (strpos($url,’?s=’) !== false ){
    $description = ‘Watch %search_query% hd porn videos for free on PornhubXvideos, Find the most relevant collection of porn videos and Sex Movies in Full HD high quality.’;
    };

    return $description;
    });

    Not Wroking

    Hello,

    Thank you for your patience.

    To get the search query and insert it in the description, please use this filter:

    add_filter( 'rank_math/frontend/description', function( $description ) {
        $url = home_url( $_SERVER['REQUEST_URI'] );
        if (strpos($url,'?s=') !== false ){
    		$search = get_search_query();
            $description = 'Watch ' . $search .' hd porn videos for free on PornhubXvideos, Find the most relevant collection of porn videos and Sex Movies in Full HD high quality.';
        };
    
        return $description;
    });

    Hope that helps.

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

The ticket ‘How to add Description for Search Results’ is closed to new replies.