0

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.

6
  • Are you talking about document title? (that's is <title> element in the HTML). If so, follow @AbhisekMalakar's advise. If your theme supports title-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 use wp_title filter. See this answer for further information.
    – cybmeta
    Commented Mar 2, 2015 at 10:40
  • Additionally, as said in the codex, post_type_archive_title() is optimized for archive.php and archive-{posttype}.php template files. It won't output the post type archive title if you use it in a static page.
    – cybmeta
    Commented Mar 2, 2015 at 10:45
  • @cybmeta I'm not talking about the <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 type Commented Mar 2, 2015 at 11:49
  • I read your question and your comments, you can be sure, but it was not clear for me what title you was talking about, that's why I asked. Anyway, as I said, you can not do that using post_type_archive_title() in a static page.
    – cybmeta
    Commented Mar 2, 2015 at 12:10
  • @cybmeta please tell me how "this has nothing to do with the title tag" is unclear to you Commented Mar 2, 2015 at 21:26

1 Answer 1

0

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
  • 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

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.