- This topic has 14 replies, 2 voices, and was last updated 8 years, 10 months ago by Xperten.
-
AuthorPosts
-
October 7, 2015 at 2:48 pm #6161XpertenParticipant
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 #6162Ernest MarcinkoKeymasterHi!
What is the title tag? If it’s custom field, then you can select it on the Advanced Options panel: http://i.imgur.com/Efg2odR.png
October 7, 2015 at 3:00 pm #6163XpertenParticipantThis is the title tag: http://tinypic.com/r/f44l83/8
October 7, 2015 at 3:02 pm #6164Ernest MarcinkoKeymasterOh 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.
October 7, 2015 at 3:05 pm #6165XpertenParticipantThanks 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 #6166Ernest MarcinkoKeymasterHi!
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.
October 8, 2015 at 3:55 pm #6193XpertenParticipantHi 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 #6207Ernest MarcinkoKeymasterI 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):
[php]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;
}[/php]I havent tested this code, but I’m hoping it will work.
October 14, 2015 at 11:18 am #6226XpertenParticipantHi,
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 #6228Ernest MarcinkoKeymasterHm, maybe it needs to be filtered with the “the_title” filter.
Try changing that code to:
[php]
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;
}
[/php]October 14, 2015 at 11:45 am #6229XpertenParticipantChanged it, but still the same 🙁
October 27, 2015 at 10:55 am #6466XpertenParticipantAny news on this?
October 27, 2015 at 1:42 pm #6483Ernest MarcinkoKeymasterLast 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:
[php]
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;
}
[/php]It works on my test environment, and hopefully on yours as well 🙂
- This reply was modified 8 years, 10 months ago by Ernest Marcinko.
October 28, 2015 at 11:08 am #6507XpertenParticipantAwesome! Thanks for the help 🙂
October 28, 2015 at 11:13 am #6508XpertenParticipantI 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.