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

This topic contains 14 replies, has 2 voices, and was last updated by Xperten Xperten 6 years, 9 months ago.

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

    Hi,

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

    Best regards,

    #6162
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    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 :)


    #6163
    Xperten
    Xperten
    Participant

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

    #6164
    Ernest Marcinko
    Ernest 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.

    Best,
    Ernest Marcinko

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


    #6165
    Xperten
    Xperten
    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 Marcinko
    Ernest 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.

    Best,
    Ernest Marcinko

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


    #6193
    Xperten
    Xperten
    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 Marcinko
    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 :)


    #6226
    Xperten
    Xperten
    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 Marcinko
    Ernest Marcinko
    Keymaster

    Hm, maybe it needs to be filtered with the “the_title” filter.

    Try changing that code to:

    
    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;
    }
    
    Best,
    Ernest Marcinko

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


    #6229
    Xperten
    Xperten
    Participant

    Changed it, but still the same πŸ™

    #6466
    Xperten
    Xperten
    Participant

    Any news on this?

    #6483
    Ernest Marcinko
    Ernest 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:

    
    
    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 πŸ™‚

    Best,
    Ernest Marcinko

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


    #6507
    Xperten
    Xperten
    Participant

    Awesome! Thanks for the help πŸ™‚

    #6508
    Xperten
    Xperten
    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.