Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Show title tag instead of page name in search results
This topic contains 14 replies, has 2 voices, and was last updated by Xperten 8 years, 10 months ago.
- AuthorPosts
- October 7, 2015 at 2:48 pm #6161
Hi,
How do I display the title tag instead of page name in the search results?
Best regards,
October 7, 2015 at 2:56 pm #6162Hi!
What is the title tag? If it’s custom field, then you can select it on the Advanced Options panel: https://i.imgur.com/Efg2odR.png
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 7, 2015 at 3:00 pm #6163This is the title tag: http://tinypic.com/r/f44l83/8
October 7, 2015 at 3:02 pm #6164Oh ok, I see what you mean. I’m not sure if that’s possible. The title tag is either generated by the theme or by a SEO plugin if you have any.
If you use a SEO plugin I can maybe check for a custom code that might work.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 7, 2015 at 3:05 pm #6165Thanks for the quick reply!
WordPress SEO Plugin by Yoast is the plugin I use π
All pages have a title tag, so should be doable in my opinion.
October 7, 2015 at 4:11 pm #6166Hi!
I’ve googled for like an hour or so, but I’m afraid it’s not possible to get it.
The wordPress codex says that there is no internal function to get the title tag of a page by it’s ID. Mainly becuase it’s a theme tag and it uses global objects, and it get’s it’s value in the site header.
I’ve tried a few different possible solutions on my test environment, but nothing works. It looks so simple, but yet it’s extremely complicated.
One thing we can try, is to generate the title tag without getting it.
If you can tell me how your title tags look like, I might be able to suggest something. What I mean is it’s structure, like for example “{blog_title} | {post_title]”
The blog title is usually there, plus there is a separator and the post title. The order and the separator is usually different. I think you can check this structure in the SEO plugin configuration.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 8, 2015 at 3:55 pm #6193Hi Ernest,
Thanks for looking into.
Do you mean like this?
<title>888casino free spins = 88 spins i oktober 2015 helt GRATIS</title>
From this page: http://freespins365.dk/888casino/
October 12, 2015 at 6:34 pm #6207I 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 :)
October 14, 2015 at 11:18 am #6226Hi,
Thanks! That solved it π
But, any reason it displays the “show month” and “show year” instead of actually shown the current month and year?
See images: http://tinypic.com/r/258bjvk/8
Best regards
October 14, 2015 at 11:42 am #6228Hm, maybe it needs to be filtered with the “the_title” filter.
Try changing that code to:
Best,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 = apply_filters( 'the_title', $seo_title ); } return $results; }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 14, 2015 at 11:45 am #6229Changed it, but still the same π
October 27, 2015 at 10:55 am #6466Any news on this?
October 27, 2015 at 1:42 pm #6483Last time I gave up after 2 hours of trying, but I checked again and great news!
I’ve finally found the function responsible to replace the variables in post names. Please try this code:
add_filter( 'asp_results', 'asp_get_seo_title', 999999, 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 = wpseo_replace_vars( $seo_title, get_post($results[$k]->id) ); } return $results; }
It works on my test environment, and hopefully on yours as well π
- This reply was modified 8 years, 10 months ago by Ernest Marcinko.
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 28, 2015 at 11:08 am #6507Awesome! Thanks for the help π
October 28, 2015 at 11:13 am #6508I tried to open a new post, but the key validator wouldn’t accept the purchase key, so I’m asking here:
How do we show the meta description or excerpt in the search results instead of some random text from the webpage?
See screenshot: http://tinypic.com/r/2uhac81/9
On the first result it has grabbed the H1 from the page, and on the second result it showing the first text from the page.
Thanks!
- AuthorPosts
You must be logged in to reply to this topic.