get_page_template()
can be overridden via the page_template
filter. If your plugin is a directory with the templates as files in them, it’s just a matter of passing the names of these files. If you want to create them “on the fly” (edit them in the admin area and save them in the database?), you might want to write them to a cache directory and refer to them, or hook into template_redirect
and do some crazy eval()
stuff.
A simple example for a plugin that “redirects” to a file in the same plugin directory if a certain criterium is true:
add_filter( 'page_template', 'wpa3396_page_template' );
function wpa3396_page_template( $page_template )
{
if ( is_page( 'my-custom-page-slug' ) ) {
$page_template = dirname( __FILE__ ) . '/custom-page-template.php';
}
return $page_template;
}
Related Posts:
- Is there a WordPress plugin that registers a plugin file as a custom page template?
- Is it possible to stop selected plugins from loading on certain template pages?
- Ways to have multiple front-page.php templates that can be swapped out?
- Template plugin for blog posts? [closed]
- Register Page Template from Plugin
- Plugin-generated pages use Not Found or Pages Archive templates?
- How to use get_template part in the plugin?
- Custom form not showing in correct place on page
- Ajax Call in page theme not working?
- How do I show content from a plugin using the template the site is currently working with?
- Pull comments from one page/post into another page/post?
- How to provide page_template path in custom plugin using WordPress
- Is there any hook for theme activation ? or something similar?
- changing posts layout in ultimate member profile plugin
- Template filter for custom taxonomy terms
- how to force tag page layout to use same as search layout?
- Show author on every sub-page
- How can I use a file in my plugin as a replacement for single.php on custom-post-type query?
- Calling the_excerpt from inside a plugin template file
- Best practice for including plugin output in a template without using shortcode?
- Timber – Twig post.content returns null can’t create ACF Gutenberg blocks
- URLs Added to ACF Repeater Field are not working
- Where to find the code used to render a page that has a shortcode and a template defined?
- How do I override plugin templates and stylesheets?
- Create custom template in plugin and display it into post template section?
- WordPress as template engine
- Default taxonomy template in plugin, override in theme
- Trying to add a page template for my custom post type from a plugin, but it will not display in the template dropdown unless file is in theme
- Plugin Admin Menu Boiler Plate
- the_content() printing DOCTYPE, and tags in the middle of page
- Opening a JQuery modal window on click of a button with a JQuery plugin
- How do I create a custom permalink structure for a page template
- How to use template inside plugin shortcode with variables for big HTML code
- Plugin create pages and use templates
- Pagination shows Same posts
- Should meta boxes for specific pages be save in their own plugins?
- Call a function for social sharing
- reCAPTCHA on page template without plugin
- Woocommerce – Change Variable Product Add to Cart to behave like external product using Custom Field (link) [closed]
- How can recognize post’s category?
- Prevent plug-in scripts on a specific template?
- How to dynamically change spots of text in custom page?
- Add custom PHP and HTML to the_content()
- How to modify the Loop from a plugin (instead of a theme)
- Multiple Post Thumbnails Plugin – Need help with code
- Show Homepage (only) Hits Count
- Wp-minify doesn’t seem to minify my JS code
- How to call php file in theme directory from plugin
- use EDD Content Restriction for restricting php in template
- Pass PHP variable to javascript
- How to makes changes on the shop/category/tag pages but not on the product pages in woocommerce?
- How can I disable an attribute from a Gutenberg block included in a template via InnerBlocks?
- How to turn my WordPress site into a ready to deploy template?
- how to display a template.php in a shortcode
- WoCommerce Cart is not showing pricing
- Give custom page template a custom post ID
- Enqueue css to a third-party plugin template
- the_posts_pagination() not working if I add wp_head() to header.php
- Mobile Menu and Mobile Sidebar missing
- How to check if short code is present in template?
- WordPress hierarchy clarification, does post_type_archive take precedence over taxonomy-term archive?
- How to add post title to custom php?
- What are the disadvantages of using template_redirect for restrictions
- How to access Post Archive created by Elementor?
- How to prevent redoing get_posts queries and make results available to other scripts?
- Programmatically generate new pages for a site based on page template and content elements accessed via DB
- Call function with button and return response
- Change Jobs for WordPress templates
- how to do Thematic like this website using wordpress?
- WordPress Product Detail and catalog
- how do i fixe Page Builder on a custom page?
- How to change the deafult template in WordPress plugin
- Plugin json page
- Customize plugin templates
- WordPress arrows dissapeared strange signs
- Template conflict with WC Payment Method
- How to use custom footer template in a site-plugin?
- Why is WP template_include overwritting all templates rather than specified page?
- How to add HTML to a template only when user is logged out/ not registered
- Passing variable from template file to the plugin file
- How to differently style pages that display posts of different category in WordPress?
- Adding a custom page template to a plugin generated page
- History of page, interval of years
- How to echo a plugin’s function into a template?
- How to add dynamic content to posts page, archive, taxonomies, search, author, etc?
- WP plugin calls for custom pages
- Custom Page Templates for a complex application – code must sit in a plugin and not the Theme
- custom template only for content
- Convert HTML5/CSS3 site to WordPress Theme (need a lot of plugins) or just use the API?
- Is there any simple wordpress search template that works with existing searchforms?
- show Visual form builder in the front end
- Fake Single WordPress Post (Page) Loop
- WordPress multisite haml templates
- How to make plugin work in each template in wordpress
- [Custom field template plugin] Upload limited to 20 inputs file
- Sort Reviews/Ratings by date on Woocommerce
- How to create a page template using custom plugin
- Make a Custom template for a specific category in wordpress
- WP Customer Reviews call short code on another page [closed]
- WordPress show different custom post type