0

I'm trying to hook a page title using is_page() and its ID 1637 along with two taxonomies serie and area. But I can't get it to work. am I missing something

code:

      add_filter( 'wp_title', 'new_listing_title', 10, 1 );

      function new_listing_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;



          return $title;
        }

        return $title;
      } 

edit : When I use this however, it does actually display the title in this particular manner(code below). How do I combine $wp_query->query_vars[] along with my code above?

global $wp_query; echo 'Car : ' . $wp_query->query_vars['serie']; echo '<br />'; echo 'Area : ' . $wp_query->query_vars['area'];

  • Have you changed parmalink structure for pages? How do you pass these serie, area variables to that page? – Krzysiek Dróżdż Dec 2 '18 at 10:08
  • Yes, I've changed the permalink structure. its currently http://example.com/used-cars/serie/area – joe city Dec 2 '18 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.