search result page title support for custom search form

#245741
  • Resolved Vijay Bhaskar
    Rank Math free

    Hello Rankmath team,

    by default wordpress search form takes us to result page with url https://domain(.)com/?s=search-term
    and page title modification with rankmath works perfectly well,

    but I have custom search form bar which takes to the results page with URL https://domain(.)com/search-results/?ad_title=search-term

    I would like to change the titles of this search page, please kindly provide support for this.
    I would like to have titles as %search_query% %sep% %sitename%

Viewing 5 replies - 1 through 5 (of 5 total)
  • Ankit
    Rank Math business

    Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention.

    Sine you are using your custom search page, Rank Math is not able to deduct it. Please use the following code and add it inside your current theme’s function.php file to get your job done:

    add_filter( 'rank_math/frontend/title', function( $title ) {
    
    	$sname = get_bloginfo( 'name' ); 
    	$getstring =   htmlspecialchars($_GET["ad_title"]);
    	$title = $getstring. " - " .$sname;
    	return $title;
    });

    Hope that helps. Thank you and please don’t hesitate to contact us if you need further assistance.

    Hello @ankit , I have added the code mentioned above , it’s working fine with search term as a title on search page. But, the issue is , it’s removing all other titles of all post types and home page.

    Hello,

    Please replace the code with the code given below:

    add_filter( 'rank_math/frontend/title', function( $title ) {
    
    	$sname = get_bloginfo( 'name' ); 
    	$getstring =   htmlspecialchars($_GET["ad_title"]);
            if ($getstring) {
                   $title = $getstring. " - " .$sname;
                   return $title;
            }
    	return $title;
    });

    This should fix the issue. Let us know if you need any further assistance.

    Thanks.

    Wonderful, it works!

    Thankyou RankMath team! Your support is wonderful!

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

The ticket ‘search result page title support for custom search form’ is closed to new replies.