2

I've set up some custom post types, and created custom archives, eg in the following format:

archive-books.php (With a template name of "Books Template"). I then have a page (/books/) created in wordpress, with the above archive-books.php assigned as the template.

How would I get the the meta title (wp_title) to be the title that I set on the page (/books/)? - At the moment it's just showing "books | sitename". Even if I change the All in One SEO custom title.

I am using All in One SEO plugin also, but that doesn't seem to work. What I THINK is happening, is that it's just ignoring the page and jumping directly to the archive-books.php as it matches the Wordpress custom post type naming rule?

3
  • 1
    Did you register your post type with has_archive set to false? Also don't name custom page templates with names that clash with default template names in the template hierarchy.
    – Milo
    Commented Jan 21, 2015 at 18:13
  • I think the problem is I want to use the plural version for both the archive, and singular post type. But then how can I set a META title on the page, without having the page url the same as the custom post type url? Eg I need to have /books/ page, so that I can set the title? Commented Jan 22, 2015 at 9:49
  • 1
    you can create a page at /books/ and set your post type rewrite also to books, there should be no conflict there as long as you set has_archive to false. you'd have to run a custom query in your page to reproduce the archive loop you'd get if you used the post type archive instead of a page. your other option is to just use the cpt archive WordPress generates and then filter wp_title to set the title to whatever you want.
    – Milo
    Commented Jan 22, 2015 at 16:36

2 Answers 2

1

Well I felt I better update this old question, the SEO plugin by Yoast now allows assigning of all SEO abilities to custom post type archives. So that's the best solution.

1
  • If this would even work. At least in combination with pods, it doesn't seem to change anything. Commented May 27 at 10:00
1

For anyone using All in one SEO plugin and registered the CPT's via PHP, here's what you can do.

In the CPT registration, inside the labels array, add;

'archive_seo_title' => 'your set title | your site',
'archive_meta_desc' => 'your meta description'

and then in your functions.php file add these 2 filters;

// CPT Archive page SEO Title
add_filter( 'aioseop_title', 'dd_rewrite_custom_titles' );
function dd_rewrite_custom_titles( $title ) {
  if ( is_post_type_archive() ) {
    $post_type = get_post_type_object( get_post_type() );
    if ($post_type->labels->archive_seo_title){
      $title = $post_type->labels->archive_seo_title;
    }
  }
  return $title;
}

// CPT Archive page meta Description
add_filter( 'aioseop_description', 'filter_aioseop_description'); 
function filter_aioseop_description( $description ) { 
    if ( is_post_type_archive() ) {
      $post_type = get_post_type_object( get_post_type() );
      if ($post_type->labels->archive_meta_desc){
        $description = $post_type->labels->archive_meta_desc;
      }
  }
  return $description; 
}

These filters will first check if the current page is a CPT archive and if it determines that it is, it will set the seo title and description to what you set in the labels array during CPT registration. If the filter does not detect a CPT archive page, then it will just return the original titles + description that is set by default.

Note: If you are not using CPT php registration, you can just make $title and $description variables equal to whatever you want, e.g.

$title = get_the_title() . ' | ' . get_bloginfo();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.