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
- Difference Between Filter and Action Hooks?
- How to create an API for my plugin?
- How to add sub-menu to a menu generated by wp_nav_menu by using plugin
- How can I add an option to the Page Template list from a Plugin?
- Explanation of the “posts_join” and “posts_fields” filter hooks?
- How do you use the plugin boilerplate loader class to hook actions and filters?
- add_filter OO with parameters
- How Can I Add a Filter to Class Instance Only?
- How to remove unwanted panels inside InspectorControls from core blocks in Gutenberg
- function triggered by “manage_users_custom_column” filter not working
- Proper way to use apply_filters() with class functions?
- add_filter and remove_filter added before and after wp_query
- Some nav-menu filters do nothing
- Determine which theme location a wp_get_nav_menu_items is for
- Filter to change the content of 404 page
- What’s the difference between hooks, filters and actions? [duplicate]
- Dynamically override page.php or single.php with custom templates using function
- Hook for post permalink update
- How to properly use a hook to create template for custom product type in a plugin such as Woocommerce? [closed]
- WordPress Media mime type filter problem 4.0
- How to add custom content under plugin row in WordPress admin plugin list?
- How to check active theme is parent or child wordpress
- Load page template with custom content using a plugin
- Define a function outside a class and call the function using action or filter hook
- Does add_filter work outside functions.php
- Synchronize Custom post type tags to WordPress default posts tags
- WordPress removing data attributes for scheduled post
- Dequeue theme stylesheets but keep widget styling on custom page template
- Change template dynamically
- WordPress after content Hook & external template part
- best practice for query string values – get_query_var always empty for my value supplied in query string
- get_current_screen() return null
- Problems with: manage_${post_type}_posts_columns
- How To Change Logout Screen Title
- ORDER BY wp_post custom column name in wp_query
- Add code inside specific wordpress standard function
- Create a free scripts and styles template within a plugin
- Check for template part, else filter content
- How to filter the_content() & include content from template
- Adding rewrite rule dynamically
- How can I turn a custom wordpress page into a product page?
- Replace youtube embed in wordpress
- Plugin-generated pages use Not Found or Pages Archive templates?
- How can I replace content in the WP Admin area before an admin page is rendered?
- How to filter content for specific content variable
- Plugin templates vs Parent Theme
- Valid filenames for add_action’s first parameter
- How do I access the menus produced by Dashboard > Appearance > Menus
- WordPress class, using add_action to call member function does not work
- How to get all queries’s results after they have executed?
- How to get the post excerpt using post object?
- hook filter after the_content on a specific page
- Bind a function with its own argument to show something dynamically after every content
- Hook add_attachment error
- 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?
- Adding filter to the title without affecting the menu title
- How to validate inputs with filter in register_setting callback
- 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?
- 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)
- Override woocommerce loop-start.php from theme using plugin?
- 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
- Add new header/footer on landing page with plugin
- Add_action not calling callback function
- 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
- Use a page as a template for a custom post type
- 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?
- Hook for plugin to show content for certain urls
- How to filter get_adjacent_post()?
- How to set custom homepage via a plugin
- post_results filter confused by pagination in sidebar and main section
- Use different archive template for plugin
- How to check during “pre_get_posts” if WP performing default query for specific custom template?
- How do I replace title with my plugin?
- wp_mail_from not changing from address
- append code after the_content not working
- Using a Page Template Not in Theme
- Find Any Theme’s page.php File
- WP Job Manager – Show recent jobs as cards
- REST API error in block editor for custom templates
- Generating Multiple Divi Pages from Database