Reply To: Show title tag instead of page name in search results

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Show title tag instead of page name in search results Reply To: Show title tag instead of page name in search results

#6207

Ernest Marcinko
Keymaster

I have come up with something that might just work.

If the SEO title is set on the Post editor, then it's probably possible to get it as post meta. Try putting this code to your themes functions.php file (to the bottom):

add_filter( 'asp_results', 'asp_get_seo_title', 1, 1 );
 
function asp_get_seo_title( $results ) {

  foreach ($results as $k=>$v) {
    // Continue if not pagepost
    if ($results[$k]->content_type != "pagepost") continue;
  
    // Get the seo title
    $seo_title = get_post_meta($results[$k]->id, '_yoast_wpseo_title', true);
    
    // Modify it
    if ($seo_title !== false && $seo_title != "")
      $results[$k]->title  = $seo_title;
  }
 
  return $results;
}

I havent tested this code, but I'm hoping it will work.

Best,
Ernest Marcinko

If you like my products, don't forget to rate them on codecanyon :)