The easiest & most sensible way I can think of, if you want the theme and plugin to be as independent as possible, is to copy the custom page template files from your plugin’s directory to the current theme directory when the plugin is activated, and delete them when the plugin is deactivated, using register_activation_hook()
and register_deactivation_hook()
.
That way you wouldn’t have to mess with the template dropdown in the page editor, and you wouldn’t have to hook into template_redirect
.
Related Posts:
- Calling a function from functions.php in custom page/ blog post
- Create page (not the post type) dynamically
- Using a Page Template Not in Theme
- Generating Multiple Divi Pages from Database
- Get page content using slug
- How can I load a page template from a plugin?
- Change the_title() of a page dynamically
- How can I add an option to the Page Template list from a Plugin?
- How to edit the properties of a page programmatically?
- Pages 404 in wordpress
- How to create custom home page via plugin?
- How to create a dynamic page based on form data with a plugin?
- Use an empty page to build custom plugin output
- Dynamically override page.php or single.php with custom templates using function
- Dropdown list of pages to get page id to store in plugin options
- Build dynamic page from cURL (HTML page) response with plugin
- How do I approach removing menu items on the fly based on settings in my plugin?
- Load page template with custom content using a plugin
- Set a specific page as 404 – not found via my own plugin
- How to Add Page Template from Plugin without Losing $this
- Create a Page via plugin
- Dequeue theme stylesheets but keep widget styling on custom page template
- How to display non-page / post content
- Change template dynamically
- Create a custom page template inside my wordpress plugin
- Problem with parameters in url and pagination
- Set page template programaticlly in plugin
- How can I pass get_the_author_meta(‘user_email’) through the REST API?
- Can Page Templates be Applied to Archive and Post Templates?
- Secure Pages Best Practice
- Custom Plugin theme filter
- Plugin generated virtual pages
- Remove sidebar on single page using plugin API
- Add Password Generator on password protected page
- ECHO Executing 4 Times In Head
- WordPress pages are not published due to External database connection with WPDB class
- my basic php code producing unexpected results
- Multiple array for post_content on plugin activation
- How to output functions from plugin inside theme
- Best way to distribute templates and code accross multiple wordpress sites?
- How to list all images used on a specific page?
- Create fixed static pages
- How to remove/replace current page template?
- Load php file with jquery in single.php
- Set page to draft on plugin deactivation
- How to create archive page to add in menu
- Load specific page when a custom URL is hit
- Plugin frontend page design irrespective of the theme used
- Conditionally check if page is using template from plugin directory
- Custom non-template page on front end fails to render
- How to save multiple values in custom post type from front end to back end
- Change Front page displays settings conditionally when user is online
- Can’t create a blank template
- Code to add template to page
- Page template compatibility with different themes
- How do I control the list of Pages an author can see?
- How to add conent (text) to Add New pages form of admin in WordPress
- auto create only 1 wp page in activate custom plugin
- Create pages for authors
- How do I use (or mimic) document.getElementById() on a page loaded from WordPress database?
- Find Any Theme’s page.php File
- REST API error in block editor for custom templates
- Problem with Owl Carousel, infinite loop [closed]
- Is there a way to decide from init whether we are on a certain backend page?
- get_template_parts() usage
- Can a WordPress plugin add read-only pages?
- Hide one specific woocoomerce product
- Problem with display data from get_option
- wp_schedule_event is registered but function isn’t running
- Empty Array is Giving Warning for array_merge()
- Custom Post Type Object – Undefined Variables
- settings api – add_settings_section not working
- Enqueue a file that’s not js or css
- WordPress Plugin Boilerplate: Addition of 3rd party scripts and styles [closed]
- Dynamic assign a custom template to custom post type posts
- How to format custom fields when editing an attachment?
- How to redirect home page to another page after login for all user?
- Woocommerce – Provide Associated Category Link for Product List Plugin [closed]
- how to create category with code in wordpress using form
- How can I call wp-load.php in my plugin file
- Avoid pages losing template association on site re-deploy
- add_filter img_caption_shortcode not implemented
- Import user data using CSV
- How to create new content type and flushes rewrite rules without visiting the permalinks page?
- How do you implement a page template automatically being applied to a page?
- Enqueueing common php scripts in a plugin
- How to add Plugin functionality in WordPress Frontend Menus
- How do I get variables from my plugin’s settings page?
- How add default term meta to prevent an error?
- plugin content on front-page only. Nowhere else
- How to get current logged-in user details in multisite?
- Check if the current user is author of first comment
- WP Plugin with Upgrade option
- Detect change in site_url and home_url
- Reporting errors in a shortcode plugin
- How can I control if post updated
- Does WordPress default CSS have Grids?
- Gravity Forms Anchor only on Front Page?
- shortcode tags not working in do_shortcode
- How to show parents of current page category, excluding the category?