Looking at the Action Reference in the Codex, the first action listed after the wp
action that sets up the WP object is template_redirect
, which is indeed fired after all queried data is available, and before a template is selected. You can use the WordPress conditionals to determine if your intended template file will be loaded.
There is also the template_include
filter which is executed after a template has been selected but before it is loaded, and gets passed the selected template file as an argument. But you should note that as this is a filter hook, it’s intended purpose is to replace a selected template rather than adding or removing functionality.
Alternately, if you are using your own theme, you could call do_action( 'my_custom_action' );
at the top of your template file and simply add hooks to the action to execute custom functionality.
Related Posts:
- What filter or action hook to use in order to load some code before the template begins printing in BuddyPress? [closed]
- When calling wp_title(), do you have to create some kind of “title.php” file?
- Set template based on query in URL
- Which has more impact on site performance? Template overrides or hooks
- Modify a function without editing template
- if page is parent page redirect to first child with hook / polylang
- How do I override the search template in 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 can I add text to a specific ‘Edit Page’?
- Genesis – Adding custom hooks to display secondary navigation
- Rewrite to load homepage for a different url
- Can i exclude certain page templates for a specific role?
- How to add description over forum list on bbpress root page
- strange behaviour of template_redirect in IE8
- Retrieving post ID from current page
- Given a page ID, how to display entire page (header/content/footer/sidebars) from a plugin hook
- Passing a parameter to filter and action functions
- Get a list of all registered actions
- Is there any way to use get_template_part() with folders?
- how to limit search to post titles?
- Hook after image is uploaded and image sizes generated
- Loading partial templates with AJAX/PJAX
- How do you use the plugin boilerplate loader class to hook actions and filters?
- A special single page templates for posts under a category and all its child category
- Where to store some per-template preferences?
- How can I tell if I’m on a login page? [duplicate]
- Restrict access to admin but allow admin_post hook
- Count singular post views automatically
- How can I hook into existing WordPress Bulk actions?
- add_action on inherit post status
- Stream Video Player does not work with do_shortcode()?
- Print shortcode in custom action hook not where the shortcode is entered
- Redirect users on specific post category or category page
- Define a function outside a class and call the function using action or filter hook
- How does wordpress blocks?
- Remove “Get Shortlink” button in admin of custom post type
- How can I show an empty WooCommerce cart? [closed]
- template_redirect not being called when using ajax
- Subpage template
- When to use actions and when to use filters
- Change location of header.php and footer.php
- add_action in functions.php, do_action in plugin?
- Same Conditionals Not Working on Two Different Hooks
- Routing dynamic numeric slug to custom template
- Is there any way of viewing revision history on files in WordPress?
- Customize profile.php
- Insert term when page is published – avoid duplicates after edits
- Capture post content before page renders
- Implement Hooks Using Array
- Templates have disappeared from drop down lists
- Use same page template for parent and child pages in a theme
- Template administration Error after WP 4.8 update
- How to access $post from a callback function
- Add action hook into wp_localize_script
- Custom template bypassing to pager to index.php
- How dynamic action login_form_{action} is working
- How to put limit on slider
- Call Web Services on post first publish
- Page template option missing
- Trying to create a template without navigation and footer
- Divs appearing everywhere in post content
- Force WordPress to NOT display the manual excerpt
- How to run a function after wp() in the wp-blog-header.php file?
- How to access deleted term inside delete_product_cat action
- Remove tags without a specific meta key from “choose from the most used tags”
- Easiest way to map content (in json) to the view (template)?
- Removing calls to noindex() and wp_no_robots()
- Replace admin header logo with an image
- Does wp_mail work in frontend tempate file?
- Dynamically generated URL and Content page
- Action hook to control access to certain parts of my site
- Custom /Page/2/ Template Only
- wordpress – modifying template to show more posts
- How to get all template files used for rendering a single post/page?
- Hook from plugin doesn’t fire up from external PHP script
- Using publish_{custom-post-type} hook for custom post type to update meta doesn’t work
- Prevent header and footer from loading on specific pages with template or plugin
- Struggling with plugin dev basics: add_action
- RTrouble passing arguments to action
- Template includes
- How Do I Unhook This Parent Theme Function?
- Two different single.php depending on source page
- Fixing media query
- I’ve installed example data on Nominee template but the published site shows another version of the site
- Count singular post views automatically
- Displaying all posts of a category in full view on one page using their single.php template
- why does not showing my custom post category list in any template?
- Locating the HTML piece of code in wordpress
- How can I insert custom html code inside a div dynamically?
- Single page applications with WordPress: routes and templates
- Inserting javascript file into theme template?
- Display different list of “Custom Templates” for each Custom Page Type
- Submit form to another template (ugly url)
- Using file outside of template hierarchy for Twitter sign in authentication
- load_textdomain won’t load my .mo file
- Cannot modify header information – headers already sent
- files disappearing from template
- why does blog page ignore template [closed]
- templates page not showing on gutenberg editor
- How to load php templates from html page (block theme)