This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Show title tag instead of page name in search results

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #6161
    XpertenXperten
    Participant

    Hi,

    How do I display the title tag instead of page name in the search results?

    Best regards,

    #6162
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi!

    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

    #6163
    XpertenXperten
    Participant

    This is the title tag: http://tinypic.com/r/f44l83/8

    #6164
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Oh 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.

    #6165
    XpertenXperten
    Participant

    Thanks 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.

    #6166
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi!

    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.

    #6193
    XpertenXperten
    Participant

    Hi 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/

    #6207
    Ernest MarcinkoErnest 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):

    [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.

    #6226
    XpertenXperten
    Participant

    Hi,

    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

    #6228
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hm, 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]

    #6229
    XpertenXperten
    Participant

    Changed it, but still the same 🙁

    #6466
    XpertenXperten
    Participant

    Any news on this?

    #6483
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Last 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 🙂

    #6507
    XpertenXperten
    Participant

    Awesome! Thanks for the help 🙂

    #6508
    XpertenXperten
    Participant

    I 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!

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.