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:
- 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
- Sending the reset password link programatically
- Custom templates not showing up in template dropdown
- Why do templates contain so many PHP tag pairs?
- Any guides on creating custom admin pages?
- What exactly does “Posts page” do in WordPress?
- WordPress Template Engine?
- How to have a custom display for both woocommerce archive and product-category pages? [closed]
- Is including the loop necessary for page.php? [duplicate]
- Blank on static home page?
- WordPress theme & site not loading after moving files
- how to show all post in my page-grid.php template page
- Adjust the results quantity for Search Results page pagination
- Is it possible to use the featured image of a page as a css background without inlining?
- Subpage template
- How to override wp-admin styling
- How to enqueue CSS and JS only on specific template?
- An unwanted inline style is added to my body tag
- Way to querry data (tags) from a wordpress database?
- How to add a php custom page to WordPress
- Mass update excerpt
- Getting pages filtered by template assigned
- How to display pictures from database?
- How do I find PHP file that contains content of my page?
- Changing permalink name redirects to another template?
- WordPress page content outside WordPress
- Can’t print Yoast meta description into page template (syntax error, unexpected ‘.’) [closed]
- Add filter multiple times using only one master function
- Need help with adding templates (archives and sitemap) to WordPress child theme
- Parsing Menu Items and Blog Posts
- Display all pages – in order
- 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
- Why is a wp function used in current PHP namespace’s callback not resolved to global scope?
- 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?
- how to display this functions?
- is_page_template showing partial results
- Adding regular php file to site
- How Do I Find & Remove H1 From Site-Title-Wrapper? [closed]
- Post repeated when opening in overlay, how do I solve this? [closed]
- Dropdown menu for categories
- Avoid pages losing template association on site re-deploy
- Removing custom sort order from admin page listing
- PHP Output also in Child theme, but different
- $wpdb->get_results breaking page?
- pass html code to worpdress
- Display additional page templates and a sidebar on plugin activation
- Getting a WordPress tag to print inside of a traditional php echo
- Why wp_remote_get() fetches certain web pages while it doesn’t work for my localhost?
- Page not visible in ‘All pages’ after being added through PHP
- Contain multiple page templates in one PHP custom template file in WordPress?
- Display metabox galleries on specific page template in admin editor
- Display WordPress archive template page in 3 columns and not 1 column [closed]
- Run do_shortcode on php template using JS function
- How to hardcode header and footer in WP?
- Display page content in different sections – based on page break block?
- How to add a full working piece of website already coded, to a large scale Website design project?
- If is_page elseif is_page not working like I want it to
- Adding styles/scripts to specific page
- loading a php file to a specific page id
- missing admin bar and widget in a template
- How to include a function in a template with template tag
- WordPress form submit to custom page template does not work
- Get current_post in reverse order with pagination
- My own theme’s custom widget areas are not working
- How to call a certain object/menubar in a PHP file
- Avada Theme – Display results from a specific category [closed]
- How can I put a custom field as the link of a button shortcode?
- why is markup routinely placed in functions in wordpress?
- I want Page titles and excerpts to show up on home.php in certain order
- ACF: Echo page title when checkbox is checked
- redirect user from login page if is logged