This is going to track only post_type
query var, but you also can add checks for query_vars
of all your post_types or only ones you would like to get a custom 404 page for.
add_filter( '404_template_hierarchy', function( $templates ) {
global $wp_query;
if ( '' !== $wp_query->get('post_type') ) {
array_unshift( $templates,
sprintf( '%s-404.php', $wp_query->get('post_type') ) );
}
return $templates;
});
Related Posts:
- WordPress post-template null warnings
- Getting only direct child pages in WordPress with get_pages
- How to add a .php file to WordPress
- Check if a menu is empty?
- Exclude pages with certain template from wp_list_pages
- Help with a custom page template – listing contents of childpages?
- Easiest way to show total number of subpages
- Switching between custom templates in a post type of the admin menu
- How can I load a PHP page without using a Template?
- how could I load a different template part by page
- Page Automatically Generated from Theme?
- How to hide all child pages with post_query?
- Change title only in dynamic page
- Populate editor with some content of a page with a page template
- Does wordpress templates always in files or in database?
- Inject class in body when particular page template is used
- Use WordPress function in php file
- Adding wrapper elements in the_date() like in the_title()?
- WordPress template page name displayed on screen
- page-slug.php not working but only for specific slug
- How do I add my PHP app to a WordPress page whilst keeping semantic URLs?
- Prevent header and footer from loading on specific pages with template or plugin
- Create a custom theme-specific page, invisible in the admin-panel?
- Execute php in pages
- Why isn’t my link attribute getting my css?
- How to refresh a template page on WordPress in 3 seconds – easiest method?
- Loop on a wordpress Page instead of content coming from the WP text editor
- Issues getting PHP to display in category pages
- My page.php shows the index.php
- How to display pictures from database?
- Dynamic content in template
- How to get the value of input hidden html from text editor to custom page template?
- Secondary navigation menu on one page
- Enable custom logo upload if logo is not in header
- How can I add an area/option for a custom page description?
- Create Page To Count Comments For Each Post In WordPress Site
- How can I edit the content in index.php? [duplicate]
- Automatic Shortcode Creation with Custom Fields [closed]
- get_the_title() gets printed out twice
- Woocommerce Show Single Product on Homepage
- How do I find PHP file that contains content of my page?
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- how to show only specific category for a template
- Show a different code on front page to other pages
- Changing permalink name redirects to another template?
- WordPress page content outside WordPress
- Using the_excerpt() on a page
- Can’t print Yoast meta description into page template (syntax error, unexpected ‘.’) [closed]
- Using same variable names in files added with get_template_part()
- Use .php file as page instead of wordpress page & template file?
- PHP include is only working in certain places in my custom WP theme
- How to get all author posts outside of author templates
- Add filter multiple times using only one master function
- Create a Blog Template Page
- Need help with adding templates (archives and sitemap) to WordPress child theme
- Showing latest post without 301 redirect
- Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)
- Show meta box only for default page template
- How to check if the current page is at a specified path in the URL?
- Is there a way to hook or call a custom woocomerce template that is not part of the default templates of woocommerce?
- Show About and Contact Us page when they’re clicked in the top menu.
- Display custom field on 404 page outside loop
- single.php with different look by category
- How to call multiple functions from multiple files into a WordPress page template [closed]
- Parsing Menu Items and Blog Posts
- How to use theme function in post/page?
- My php code is not being executed
- the_content of template page
- Display all pages – in order
- How do I define a lookup table that will work across all PHP elements of the template?
- trouble with page_id & highlighting current page
- Apply class to every third list item? [duplicate]
- How to include custom code on a page that’s set to act as homepage?
- Editing a PHP file to include a small text piece on every page
- persist a variable set in header.php all the way down to footer.php
- Can a page contain php code?
- What’s the best way to include PHP code in pages?
- Function Reference Documenting Template Tags for use in Custom Theme Templates?
- Removing WordPress Footer -without access to PHP code?
- How to set a template with wp_insert_post
- Automatically add images to a menu
- Why is a wp function used in current PHP namespace’s callback not resolved to global scope?
- Why does the Woocommerce grouped template prints the unpublished products?
- Adding conditional text to a PHP Shortcode Template
- Create page template via functions.php?
- Short code template + ajax
- What’s a good way to allow overwriting files within a child theme if I want the same folder structure?
- Need php code’s output to display underneath a Divi Module
- Insert page content into another page with a changed variable
- how to display this functions?
- is_page_template showing partial results
- Adding regular php file to site
- Advice on creating a WP Archive Template with Custom Taxonomy (get_term_meta)
- add_filter function concatenate string and locate_template function
- How to render a block from php template
- Template Loop – add switch case php
- How to echo every parent page title?
- Use same page-mypage.php template for several pages
- get_page_template_slug returns incorrect path
- How Do I Find & Remove H1 From Site-Title-Wrapper? [closed]