So lets say you have a static home page and your posts page is a page called "Blog" or something along those lines. Using <?php post_type_archive_title(); ?>
in the header.php will then allow the heading of the "Blog" page to show correctly as "Blog" instead of the first post name, and also displays single static pages correctly. How do I go about replicating that for custom post types? I'm trying to avoid using loops in the header.
1 Answer
Have you tried add_theme_support( 'title-tag' ); And remove the title tag from your theme, and call the wp_head() at proper place.And let wp handle the title tag for you.
-
1. learn to wrap your code in proper formatting. 2. this has nothing to do with the title tag 3. theme support for title tag already in place 4.
wp_head
is in it's proper place Commented Mar 2, 2015 at 7:57
<title>
element in the HTML). If so, follow @AbhisekMalakar's advise. If your theme supportstitle-tag
you have to avoid the direct use of<title>
in the header.php because it is added by WordPress. If you need to modify it you have to usewp_title
filter. See this answer for further information.post_type_archive_title()
is optimized forarchive.php
andarchive-{posttype}.php
template files. It won't output the post type archive title if you use it in a static page.<title>
tag (if you actually bothered to read my reply to him) I'm talking about the page title and other data relevant to that page that I can access when I set a static page to display blog posts that I want to replicate for a custom post typepost_type_archive_title()
in a static page.