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
- How to use Class
in Java? - Get name of the current template file
- How do you find out which template page is serving the current page?
- How to change the default registration email ? (plugin and/or non-plugin)
- Passing a parameter to filter and action functions
- Difference Between Filter and Action Hooks?
- How to know what functions are hooked to an action/filter?
- How do I get the size of an attachment file?
- Get a list of all registered actions
- what is correct way to hook when update post
- Is there any way to use get_template_part() with folders?
- Is there a hook that runs after a user logs in?
- how to limit search to post titles?
- How to enqueue scripts on custom post add/edit pages?
- How can I edit post data before it is saved?
- Difference between do_action and add_action
- Trouble understanding apply_filters()
- How can I see all the actions attached to an “add_action” hook?
- Which hook should be used to add an action containing a redirect?
- get_template_part vs action hooks in themes
- Why do some hooks not work inside class context?
- Adding Page Attributes Metabox and Page Templates to the Posts Edit Page?
- Difference between after_setup_theme and init action hooks?
- How can i change email template for new user
- Any advantage to using get_header() over include(‘header.php’)?
- Enable page templates. How?
- Is it possible to override the result of get_template_part()?
- Is there any action filter/hook for validating a custom field before publishing the post?
- Use [embed] filter in template files
- Trigger custom action when setting button pressed
- What’s the purpose of the paged.php file?
- How do you access the Product Short Description in a WooCommerce email template? [closed]
- Please explain how these hooks work
- Prevent comments_template() to load comments.php
- How many filter/action hooks are healthy?
- Is there a way to list all used/unused WP templates?
- Earliest hook to reliably get $post/$posts
- Page editor missing Templates drop down
- Print WordPress template filename(s) for debugging
- Hook after image is uploaded and image sizes generated
- How to add a new product type on woocommerce product types? [closed]
- How to force TinyMCE in WordPress to replace newlines with tags and not with
- How to find the posts page (home page) programatically
- WooCommerce: Change template for single product page
- What does (10, 2) mean when used with add_filter
- View WordPress page template usage (or unused)
- add_action(‘wp_ajax_[action name]’, myfunction) problem
- WordPress Multisite: Adding actions to only one site
- How to edit contents of dynamic_sidebar()?
- How to only hook on Single.php after content?
- How to check if a shortcode exists?
- Where is get_header(‘shop’) file in Woocommerce templates
- Custom templates folder
- How to remove action hook done in a plugin from functions.php in my theme?
- Valid characters for actions, hooks and filters
- What is the link to my default “archive” page?
- How to check if a hook is hooked or not?
- Extract image from content and set it as the featured image
- trigger save_post event programmatically
- How to get slug of current category in taxonomy template?
- Implementing advanced add_* function wrappers
- How to show a under construction page for a domain but still be able to work on index.php?
- Change the name of the ‘Default Template’
- Customizing get_the_excerpt() to specific length and “Read More” output.
- My add_action (wp_footer, ‘method’) is not calling?
- How to Rename a Template File?
- get page templates
- Hook/action after WP_Query gets posts to query custom tables for post-related meta
- What is the earliest possible hook for safely using `is_front_page`?
- Echoing Elementor page content in template, but it doesn’t get styles and some widgets are missing
- Using WordPress templating for HTML emails
- When can you get current page ID and initialize hooks right after?
- Getting instance variable in scope of ‘wp_enqueue_scripts’
- Perform action on WPMU blog deletion
- Loading partial templates with AJAX/PJAX
- Unregister post type from child theme
- WP frontend output of custom textarea fields not respecting line breaks. In admin it’s OK
- How do you check if a WordPress template file exist?
- How do you use the plugin boilerplate loader class to hook actions and filters?
- Add action hook conditionally – only when home.php in use
- Load entire NextGEN gallery from single thumbnail?
- How to check if which hook triggered the call to a function?
- I put my blog on a subpage, how do I get page title?
- Send data to 3rd party api with wp_remote_post on wp_login