Further contemplation, and looking at the template hierarchy, lets me know that every theme needs at least a page.php, or singular.php, or the index.php file is used.
So, I just need to figure out the current theme directory (via get_theme_directory function), and see if the page.php file exists. If so, use the code from that template as the basis for the new template.
If it doesn’t exist, then look for and use singular.php and index.php in that order.
And if that doesn’t exist, the theme has problems, and probably wouldn’t work correctly.
So, there is no need to figure out what template a theme will use for a page. They will have a page.php (or a page-something.php, which I can look for).
Related Posts:
- How can I load a page template from a plugin?
- How can I add an option to the Page Template list from a Plugin?
- Hook in wp.media to add a new tab
- Overide get_template_part( ‘partials/post’, ‘sidebar’ ); with a plugin
- What’s the earliest point I can get the queried object ID?
- Using Primary Color in Plugin Block
- Using a Theme inside a Plugin directory
- Plugin development without Theme adjustments?
- What is the best way to provide plugin users with a way to customized the styles
- How to create custom home page via plugin?
- Dynamically override page.php or single.php with custom templates using function
- Is it possible for a plugin to register a page template file?
- Programmatically Selecting Theme Based on URL
- How to properly use a hook to create template for custom product type in a plugin such as Woocommerce? [closed]
- Calling a function from functions.php in custom page/ blog post
- Build dynamic page from cURL (HTML page) response with plugin
- Fully automated theme install and activation via a plugin
- Load page template with custom content using a plugin
- How to Add Page Template from Plugin without Losing $this
- Calling plugins API within a theme
- Hook into theme-switching later than `setup_theme`
- Dequeue theme stylesheets but keep widget styling on custom page template
- How to display non-page / post content
- WordPress security issue to output data from user input from theme option form
- Which themes do you use to test compatibilities with your plugin [closed]
- Change template dynamically
- 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?
- How to Debug: My Plugin Interferes With My Theme
- Theme Install using a Custom Repository
- Plugin-generated pages use Not Found or Pages Archive templates?
- Custom Plugin theme filter
- Auto-Populate Image After Media Upload
- How to create a backend for a custom theme?
- How to make “upgrade safe” theme for a plugin?
- Remove sidebar on single page using plugin API
- Are there any official or unofficial guidelines for the styling of a widget?
- my basic php code producing unexpected results
- Create page (not the post type) dynamically
- How to output functions from plugin inside theme
- Best way to distribute templates and code accross multiple wordpress sites?
- Get images / media attached to a page by page ID
- Create fixed static pages
- How To Protect Plugin Display From Being Affected By Theme’s CSS
- How to remove/replace current page template?
- Load php file with jquery in single.php
- Displaying custom content from a plugin within the active theme
- Getting Post ID at “stylesheet” and “template” hooks
- WordPress admin panel not working
- Override category archive page title (not the head title)
- Conditionally check if page is using template from plugin directory
- How to hide/remvoe unnecessary field/section in post edit section ( Dashboard )
- How to save multiple values in custom post type from front end to back end
- Redirect theme directory to plugin theme directory
- Adding and handling custom settings tab to fusion element
- Change Front page displays settings conditionally when user is online
- Can’t create a blank template
- Code to add template to page
- Post Pagination does not working on WP-Query
- Page template compatibility with different themes
- Managing Custom Designed Content
- Create and style menu
- Developing Themes on WordPress, Looking for Excellent Tutorials [closed]
- Using a Page Template Not in Theme
- REST API error in block editor for custom templates
- Generating Multiple Divi Pages from Database
- Unit testing for plugin development
- How would I create a plugin for my shortcodes?
- Save metabox with multiple checkbox array
- How does uninstalling WordPress plugins work?
- Error with Custom Admin Screen in iframe Thickbox
- How to list events by category and month with plugin Event Organiser?
- Find source of notice / warning / errors efficiently
- Sharing common functionality (functions, template parts) between plugins and themes?
- Use wp_set_post_terms() instead of wp_insert_post()
- Create a free scripts and styles template within a plugin
- Elementor custom Query with ACF fields to show matching woocommerce products custom fields
- How to enqueue style in WordPress plugin from theme files?
- pre_get_post alter current post id
- Remove Default Blogroll Links via Plugin script
- Catching Form Submission in WordPress Admin Panel
- I receive taxonomy id
- Filter posts in pre_get_posts order by meta value date (desc or asc)
- Save temporary registration data
- Activate / Deactivate plugin
- Serial Number from custom table not appear in woocommerce_email_before_order_table action
- Always hide a page from the menu
- Author Meta in Author URL Link
- Update database record in plugin
- get_comment_meta() for a filter hook in a plugin
- form does not generate $_POST request
- Callback function quicktags that uses variable in start tag
- Font Awesome stopped showing icons, shows &# text instead [closed]
- Can I use a hook other than ‘init’ to handle form submissions?
- Stop theme displaying comments
- Plugin capabilities
- Deactivate plugin on registration
- How to filter manage categories listing