As you describe the timing would not quite work. During WP core load:
- main query is created and processed into query variables (with
pre_get_posts
being one of the hooks able to influence the results) - then
template-loader.php
uses conditionals (dependent on those query variables) to determine template to use
So at the point of pre_get_posts
you cannot technically check for template choice, because that is not happened yet. However what you can check for – is query variables are those that correspond with that template being chosen down the road. Which is practically quite close.
Related Posts:
- Looking for WordPress System Diagrams
- How can I load a page template from a plugin?
- Overwrite theme file from plugin
- How to control output of custom post type without modifying theme?
- When is it appropriate to put functions on page template vs. functions.php?
- Filter to change the content of 404 page
- Change of query var in pre_get_posts not maintained
- How to properly use a hook to create template for custom product type in a plugin such as Woocommerce? [closed]
- How to check active theme is parent or child wordpress
- WordPress removing data attributes for scheduled post
- Is there a way to loop through a shortcode datasource to create a table?
- creating custom archive template within plugin for custom post type using archive_template filter
- Where to call wp_enqueue_script in a plugin with custom template?
- Can Page Templates be Applied to Archive and Post Templates?
- ORDER BY wp_post custom column name in wp_query
- Create a free scripts and styles template within a plugin
- How can I turn a custom wordpress page into a product page?
- pre_get_post alter current post id
- Plugin templates vs Parent Theme
- How to make “upgrade safe” theme for a plugin?
- 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 create templates for a custom module to show on the front end within my theme?
- Why aren’t some plugin styles loading when I load a template?
- Plugin custom post template; without overriding all posts
- Best way to distribute templates and code accross multiple wordpress sites?
- Load php file with jquery in single.php
- Setting post_id for single.php based on URL without a redirect
- 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?
- Add WordPress Meta Box saved form input to WordPress RSS feed [duplicate]
- Javascript not being loaded only in custom taxonomy template
- Add new header/footer on landing page with plugin
- Use a page as a template for a custom post type
- Page template compatibility with different themes
- How to set custom homepage via a plugin
- Template file structure , wordpress hook for altering the template
- Can a plugin differentiate syndication feeds from actual site views?
- How to use get_pages( ) correctly with ‘child_of’ to replace page with child page
- 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
- WP Job Manager – Show recent jobs as cards
- Help interpreting @wordpress/create-block-tutorial-template usage error
- Update Option Stored in Multi-Dimensional Array
- Best practices for using the transients API
- $wpdb->insert_id
- Remove profile picture option (and other things) from profile.php (in admin)
- How Can I Add a Filter to Class Instance Only?
- Getting old term value with edited_{$taxonomy} | Hook
- Call activation hook multiple times
- Adding custom code into header.php using a plugin
- Two-step login process – Is it possible?
- Unified Approach for Placing Option Pages
- Define a function outside a class and call the function using action or filter hook
- Modifying WordPress plugins
- On plugin deactivation hide its shortcode
- Can I submit a plugin that follows the PSR-2 coding style guide?
- Verify Nonce returns false – Request Nonce returns correct value
- How to untrash a post only if it was not a draft?
- Can I change header.php of current theme through a plugin function?
- Gutenberg blocks not getting styled on back end
- Writing a plugin which needs to upload files
- Calling is_single() outside the loop
- update woocommere total value on checkout based on selected payment method
- Add a Save Button to Custom Meta Box [duplicate]
- Gutenberg: import dependency or assign from global variable?
- Following WordPress Markup Is mandatory, got awkward resultyby wordpress standard markup?
- Steps to Update a WordPress Plugin That We Developed
- Using WAMP, trying to create a plugin, getting error: You do not have sufficient permissions to access this page
- Loading Modernizr (or other JavaScript libraries) for use in a plugin
- Issue on Setting $icon_url Parameter on WP add_menu_page()
- I have this error notice ‘wp_enqueue_script was called incorrectly’ in my plugin
- Logout after clicking URL link results in “headers already sent” error
- wpdb->get_var always returning 0
- A function that will remove HTML and tags from a string?
- $wpdb->prepare is not working like mysql_real_escape_string
- Enqueue ONLY Plugin Styles and Scripts
- Setting a post’s category
- Remove Products From Category
- Using WordPress with WP Statistics for QR code usage survey
- Integrating a Gutenberg custom block within a larger plugin
- How to do admin ajax request in a plugin for rest api
- Add default value from selection
- How can I create a wp plugin with this code
- admin-post.php form handling only working when logged in as admin
- Gutenberg component in a plugin admin
- Custom Admin Plugin – Injecting repeatable select fields (add, remove) into an Ordered List
- Add_action not calling callback function
- React in plugins: REST endpoints vs. regular functions
- WordPress function is not called and ajax return 0
- Post Pagination does not working on WP-Query
- Plugin options page: grouping checkboxes
- Issue on Getting WP Gallery Items In cpt-single.php As Attachments
- Plugin translation not being displayed
- Show Metabox Images in slideshow instead of static
- Deactivate plugin on registration
- How to filter manage categories listing
- How to remove a class [closed]
- I want to redirect user to an amazon product page from my wordpress website when they add product to there cart [closed]