In fact there is, using template_redirect, which you would put in the functions.php file – Here’s what I use:
function uniquename_default_template() {
if(get_post_type() == 'posttype') : /* You could use is_single() instead of get_post_type() == '' or any type of conditional tag) */
include(TEMPLATEDIR . 'path/to/theme/file.php'); /* You could use TEMPLATEDIR to get a file from a template folder, or PLUGINDIR to get a file from the plugins directory - doesn't support HTTP requests */
exit; endif;
}
add_action('template_redirect', 'uniquename_default_template');
The above code checks for a post_type called posttype, if it is, it will include the PHP file specified in the include statement by redirecting the template using the template_redirect function.
Related Posts:
- Opinions and recommendations on the best barebones base theme [closed]
- Display a specific dynamic sidebar widgets on a specific page
- Customizing page content layout
- Putting two themes together to create a complete site
- Using the same database on another Subdomain
- How to create custom layouts and static pages in themes for clients
- Theme Dev | Convert Template to Theme
- Create a child Theme or custom Theme
- wordpress template page Usage [duplicate]
- How to Link External jQuery/Javascript files with WordPress
- Dynamic template serving, change theme_root using add_filter from current theme
- Custom Taxonomy-specific JavaScript
- How to override the “inc” folder (or any folder) in a theme using child theme?
- Is it possible to access Gutenbergs reusable blocks in CPT block templates?
- Building useful features into your theme
- Editing theme files and access to the Code pages only to super-admin?
- Change Default Image HTML
- Custom Page Template [closed]
- Make page template that is just an “include” of another?
- Extra User Profile Field Upload File / Image
- Selecting An image from the Media LIbrary on the frontend
- Can I obtain differents links for different installed theme?
- Theme Activation, Create Database Tables
- Will activating a different theme preserve custom settings to current theme?
- WordPress ignoring specified template for front page. Why?
- How to trigger function on theme delete?
- Setting a static home page and blog page without using the settings
- Two Navigation Menus – secondary nav is including main nav
- Added a new template file to a theme – get Call to undefined function error
- Possible to put header-{your_custom_template}.php in subdirectory?
- Renaming the Twenty Fourteen WordPress theme
- Protect changes made to the theme when updating
- How to find a file in WordPress themes [closed]
- How to use get_page_by_title() with qTranslate?
- How to set a single theme directory on a multisite blog?
- Child theme Page Template not loading
- Multi-level page hierarchy
- Get WordPress to use another custom “author.php” file (“custom-author-file.php”)
- How to customize core admin pages within a theme?
- Static page not working
- Custom options below pages/posts editor?
- How to get custom page template being edited in gutenberg editor
- Own Theme Customizer displays error message when saving, saving still works
- Best practice – pages – ACF or inline coding
- Migrating a taxonomy’s tags to the native category
- Search form not finding content in template page
- Different logo on homepage
- the_content() is not displaying content, why? [closed]
- display comment form for specific post id
- Selected template is not respected for home page in WordPress
- Tips for managing code when developing a parent theme framework
- Is there a way to upgrade a theme without losing custom templates?
- Need help with making a website where user can add products
- How to restore file or theme?
- What’s a good way to unenqueue all scripts for a single template page?
- How to transform a custom made static HTML website to a WordPress website [closed]
- Template for landing pages
- Trying to uninstall a theme, but it’s hijacking my home page
- Most wp_nav_menu parameters ignored
- Trying to fix a website that was built with WordPress and then taken off of it
- Create theme for mobile phones and tablets only?
- Create a Page template selector page
- Setting a new default template for the creation of a page
- Conditional config WP_HOME/WP_SITEURL does not update bloginfo(‘template_url’)?
- Multiple sub directories for theme template pages
- How to remove the tripadvisor logo from the wordpress theme?
- Custom fields not displaying on front end
- My blog suddenly can’t find my stylesheet?
- Is there any way to modify images from a theme using the web interface?
- Please help me clear my confusions about WordPress
- WordPress keeps switching back to empty template
- Removing a widget via theme editor
- How do I target this page specifically?
- Custom CSS is overwritten by WordPress?
- Default and warning messages & no login
- dynamic image path within a javascript file
- WordPress Twenty-Fourteen: How to Remove Home Page Header Image from Other Pages
- Display ads by location [closed]
- WordPress Dashboard Problem [closed]
- Use another theme template in my theme
- Show posts from all categories
- Allow arbitrary text after page URL
- Revamping a WordPress mirror site – and I don’t know where to start!
- Best way to create a page outside of the pages list
- adding a unique page to an existing site
- Will this js code work in a page template?
- Custom single page based on which custom page template is selected
- How to find out which template the HTML content comes from?
- How to modify/ customise NextGen Gallery’s templates? [closed]
- separate home page into separate pages
- Overwrite template-tags.php in child theme
- Static front page displaying twice
- What happens to bespoke page template references on theme change?
- How to add sidebar to homepage programmatically?
- How to apply styles to the custom page template
- Static posts page is not working
- My website is generating weired url parameters of paginated pages
- Get header/footer list for a theme
- Homepage not loading correctly, only after refreshing
- Create a page for each database table entries