You can use the theme_page_templates
filter to add templates to the dropdown list of page templates like this:
function wpse255804_add_page_template ($templates) {
$templates['my-custom-template.php'] = 'My Template';
return $templates;
}
add_filter ('theme_page_templates', 'wpse255804_add_page_template');
Now WP will be searching for my-custom-template.php
in the theme directory, so you will have to redirect that to your plugin directory by using the page_template
filter like this:
function wpse255804_redirect_page_template ($template) {
if ('my-custom-template.php' == basename ($template))
$template = WP_PLUGIN_DIR . '/mypluginname/my-custom-template.php';
return $template;
}
add_filter ('page_template', 'wpse255804_redirect_page_template');
Read more about this here: Add custom template page programmatically
Related Posts:
- Can Page Templates be Applied to Archive and Post Templates?
- Best way to distribute templates and code accross multiple wordpress sites?
- Load php file with jquery in single.php
- Change Front page displays settings conditionally when user is online
- Page template compatibility with different themes
- get_template_parts() usage
- How to make “upgrade safe” theme for a plugin?
- WordPress class, using add_action to call member function does not work
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- How to get all queries’s results after they have executed?
- How to get the post excerpt using post object?
- Remove sidebar on single page using plugin API
- Remove an action by extending class and replacing it
- hook filter after the_content on a specific page
- Bind a function with its own argument to show something dynamically after every content
- my basic php code producing unexpected results
- Create page (not the post type) dynamically
- Hook add_attachment error
- Call to undefined function is_home() or any conditional tags
- How to create templates for a custom module to show on the front end within my theme?
- WooCommerce change Tax Class programmatically when Recalculating an existing Order [closed]
- Update variable value via add_filter
- Why aren’t some plugin styles loading when I load a template?
- Plugin custom post template; without overriding all posts
- Make wordpress join default user metas with a column from another table while displaying the wp_users table on the users screen
- How to output functions from plugin inside theme
- Configure WordPress to Generate Scheme-less Relative URLs
- Gravity Forms Anchor only on Front Page?
- How to find list of all functions bind to a particular hook from my plugin?
- Include HTML (Bootstrap Modal Box) with a plugin into my header
- WP_NAV_MENU filter targets all menus
- How do I show content from a plugin using the template the site is currently working with?
- How to remove/replace current page template?
- Adding filter to the title without affecting the menu title
- How to validate inputs with filter in register_setting callback
- How do i remove the title from a specific page
- Can / should a widget plugin define its own Widget Area?
- How to get changed post title in my custom plug-in which fires when ‘save_post’ is called?
- Is there an action_filter hook to add content before the post title?
- Adding tables to dashboard pages programmatically?
- Can I attach a plugin via my add_filter callback contents?
- apply_filters() and call_user_func() to define and call a function outside a class
- add_filter postbox_classes multiple post types
- Override category archive page title (not the head title)
- Limit get_next_post to posts from the same author
- Override woocommerce loop-start.php from theme using plugin?
- Conditionally check if page is using template from plugin directory
- Any way, hook to add content right before the “read more” link?
- Overriding the template files using a plugin for all themes
- How do I use a plugin to swap out the template file for a custom post type?
- WordPress Plugin Boilerplate – add actions and/or filters based on user’s role
- How to save multiple values in custom post type from front end to back end
- Javascript not being loaded only in custom taxonomy template
- Add new header/footer on landing page with plugin
- Redirect theme directory to plugin theme directory
- WordPress Reset password Strength set to medium
- login_message filter not working
- Can’t create a blank template
- Add_action not calling callback function
- How can I load Template file from wordpress plugin
- I have a plugin where in I have to change the title of the page dynamically by sending parameter to the_title filter
- WordPress Dropdown image select
- Modify search form with plugin
- Code to add template to page
- Use a page as a template for a custom post type
- Single_template for a custom post type created from a plugin is returning an empty page
- get_comment_meta() for a filter hook in a plugin
- Which filter to use to pre-parse form elements, which are generated by plugin’s shortcode?
- Custom signature appears twice on page
- Caption Shortcode: what filter to change the image size?
- Confusing $tag specification for apply_filters call, in core options.php code
- Hook for plugin to show content for certain urls
- How to filter get_adjacent_post()?
- How to set custom homepage via a plugin
- Template file structure , wordpress hook for altering the template
- WordPress permalink setting
- post_results filter confused by pagination in sidebar and main section
- Displaying External Data – Not Posts
- Making plugin output customizable
- Use different archive template for plugin
- How to display custom taxonomy and terms using/creating plugin template
- How to check during “pre_get_posts” if WP performing default query for specific custom template?
- How do I replace title with my plugin?
- Apply Filters Causing a 500 Internal Server Error
- wp_mail_from not changing from address
- append code after the_content not working
- add_filter adds output in the head
- Apply function on all action hooks?
- Using a Page Template Not in Theme
- Find Any Theme’s page.php File
- WP Job Manager – Show recent jobs as cards
- Help interpreting @wordpress/create-block-tutorial-template usage error
- Do Not Back Up? Is there any accepted way to tell backup and clone plugins to skip a certain file? [closed]
- Ninja Forms: Front-End Forms, Post ID?
- REST API error in block editor for custom templates
- How to provide page_template path in custom plugin using WordPress
- Generating Multiple Divi Pages from Database
- Custom post type template not loading from plugin
- Attributes array not saving values
- ‘global’ not working when passing variable from plugin file to template