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
- Theme / Divi change visitor css and site logo and all site urls based on REQUEST_URI non logged in wp user
- get_template_parts() usage
- How to give a NavWalker its own stylesheet?
- How to display a product features dynamically with icons?
- Add function after the_content
- unregister_setting() vs delete_option() for plugin update
- wp_schedule_event custom event time
- Multiple array for post_content on plugin activation
- Ajax: Populate with content from a post’s ID not working – duplicating current page html instead
- WordPress shortcode using WPB_GET_IP
- update_post_meta doesnt update template
- Best way to include and use Zoho SDK in a wordpress plugin
- Data not insert and update through ajax and jQuery in admin page?
- How to change WooCommerce loop product title HTML output in single product page and archive page
- Using AND and bracket grouping in SQL not working
- Taxonomy archive page listing terms instead of posts
- How to make and save custom form in custom plugin page?
- How to make my shortcode load scripts and styles, from within the plugin?
- Plugin language always shows WP site language, not profile language
- Class cannot be found, but it’s available in the file, I get: Fatal Error: Uncaught Error: Class ‘Blocks\Base\Activation’ not found
- how to change image of jquery slider plugin
- Can woocommerse be used dynamically for billing from another plugin for payment processing?
- Is hint for translator compulsory while internationalizing a string containing variables?
- Sending an SMS on new order placed – WooCommerce
- Update variable value via add_filter
- Settings API: Setting default option via ‘get_option’ fails
- Show content without a post
- Setting a JSON web token from a secondary api as a secure cookie on WordPress
- How to create a digital product download link that can’t be used twice?
- WP ajax requests not stacking?
- How to save post meta as an array in Gutenberg?
- How to redirect to login page when user not loggedin on a particular page