php - How to display custom seo title before the loop?

admin2025-06-05  2

So I've optimized one of my archive page title to this

       add_filter('wpseo_title', 'new_filter_title');

      function new_filter_title($title)

      {
        if ( is_page('1637') && $id = get_queried_object_id() )
        {

          $locations = get_query_var('area');
          $location = get_term_by('slug', $locations, 'area');
          $models = get_query_var('serie');
          $model = get_term_by('slug', $models, 'serie');

          $title = '';

          if($model && $model) $title .= $model->name . ' Used';
          else $title .= 'Used';

          $title .= ' Cars For Sale';

          if($location && $location) $title .= ' In ' . $location->name;

          $title .= ' on ' . get_bloginfo('name');



          return $title;
        }

        return $title;
      }

and this works perfectly. So what I'm trying to do now is echo the same title in the page before the loop. how do I this?

I've already tried this solution

echo get_post_meta(get_the_ID(), '_yoast_wpseo_title', true);

That didn't work. it instead returned variables %%title%% ........%%sitename%%

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749116327a316500.html

最新回复(0)