Dynamic Tag Archive Title in Pro Header Headline Element

Ahhh. :man_facepalming:t2:
I totally forgot that I had added that code to the functions file!!! Geez. thank you for your explanation and follow-up.

My pleasure, @stuartborders.

While this works great for the archive of the post type (and I am very thankful), I am having an issue with assigning a header to ā€œAll Refurbished Hardware Postsā€ or other post types. Generally only a couple of them show up in the selection area in the header admin. Am I missing something? Is there another ā€œis_post_type_archiveā€ type function I can use to assign the headers to the correct post type single post?


Is an example of a header I canā€™t assign.

Hello @stuartborders,

You can edit the code shown by @Christian and insert this another condition:

if ( is_post_type_archive('refurbished-hardware') || get_post_type() == 'refurbished-hardware' ) ) {
  
  match = 1234;

}

This condition will assign header 1234 to the ā€œrefurbished-hardwareā€ archive or any single post that the post type is ā€œrefurbished-hardwareā€.

For reference, please check out the codex: https://developer.wordpress.org/reference/functions/get_post_type/

I already use if ( is_post_type_archive('refurbished-hardware') {} to match on the archive. Adding get_post_type() to the condition makes it work on the single post, but over writes the archive post header. I am trying to have

  1. A header for the archive that is specific to that post type and not using dynamic text
  2. A header for the single post that puts the title into the header dynamically

#1 already works fine thanks to a previous thread.

#2 usually I would use the gui in the header builder to select ā€œAll Refurbished Hardware Postsā€. Unfortunately (I assume due to the number of posts on the site) it does not load all of the Post Type options. It would be nice if the search could work where I could select this option. its such a nice feature. However I am left trying to code it in the functions, which is fine. I just canā€™t get it to differentiate between #1 and #2 scenarios.

Hello @stuartborders,

Not all post types will load in the header builder. That is why you need to have a custom condition to resolve it. We recommend that you have this condition:

if ( is_post_type_archive('refurbished-hardware') ) {  
  match = 1234;
} else if ( is_singular('refurbished-hardware' ) ) {  
  match = 5678;
}

This way you will have a dedicated header for the post type archive, you also have another header for the single post type page.

Hope this helps. Kindly let us know how it goes.