Once a fucntion has been hooked to an action, the function will be executed every time the action is called (with do_action
). To stop this, the action should be removed. See remove_action
:
function do_entry() {
if ( get_the_title() ) {
add_action('loop_entry_before', 'function_that_adds_h2_structure');
} else {
remove_action('loop_entry_before', 'function_that_adds_h2_structure');
}
add_action('loop_entry_entry', 'function_that_adds_content_structure');
}
In your case, I think that the actions hook approach is not very good and it can be better to do direct function calls:
function do_entry() {
if ( get_the_title() ) {
function_that_adds_h2_structure();
}
add_action('loop_entry_entry', 'function_that_adds_content_structure');
}
Related Posts:
- the_content and wp_link_pages
- Count singular post views automatically
- Combining action and filter?
- need help looping add_action in wp
- Query Nopaging action not having effect
- Custom Header added within Dashboard pages, is this possible with custom template files?
- Count singular post views automatically
- An action that runs after each post in the loop on index/archive page?
- Best hook for a function which adds shortcodes to the system?
- Hook in the loop after the first post
- Add “New” Sale badge to products in WooCommerce based on creation date
- How to fix pagination for custom loops?
- Jquery Slider for profile template
- Counting the posts of a custom WordPress loop (WP_Query)?
- 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?
- Get a list of all registered actions
- if ( is_home() && ! is_front_page() )
- what is correct way to hook when update post
- Get excerpt using get_the_excerpt outside a loop
- Is there a hook that runs after a user logs in?
- How to display Yoast SEO meta description in archive template for each post instead of the_excerpt()? [closed]
- 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?
- Get post content from outside the loop
- Why should I put if(have_posts()), is while(have_posts()) not enough?
- Difference between do_action and add_action
- Display featured products through custom loop in woocommerce on template page
- Split Content and Gallery
- Trouble understanding apply_filters()
- How can I see all the actions attached to an “add_action” hook?
- How to get Author ID outside the loop
- 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?
- Difference between after_setup_theme and init action hooks?
- How can i display the content in plaintext
- Redirect loop when trying to login to /wp-admin/ [duplicate]
- How to split a loop into multiple columns
- Is there any action filter/hook for validating a custom field before publishing the post?
- Is it necessary to reset the query after using get_posts()?
- Trigger custom action when setting button pressed
- Please explain how these hooks work
- Is there any difference between the_title() and echo get_the_title()?
- How many filter/action hooks are healthy?
- AJAX with loop filtering categories
- Earliest hook to reliably get $post/$posts
- Do I need to use The Loop on pages?
- Remove the Homepage Query
- remove tags from the_content
- Hook after image is uploaded and image sizes generated
- the_title() shows title of the first post instead of the page title?
- How to force excerpts / teasers in the loop
- What does (10, 2) mean when used with add_filter
- add_action(‘wp_ajax_[action name]’, myfunction) problem
- WordPress Multisite: Adding actions to only one site
- Retrieve each widget separately from a sidebar
- How to only hook on Single.php after content?
- Why am I being limited to ten posts on a custom loop?
- How to remove action hook done in a plugin from functions.php in my theme?
- Valid characters for actions, hooks and filters
- Should I use loop in the single.php file?
- A search for ‘0’ returns results
- 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
- Implementing advanced add_* function wrappers
- Why do themes rely on “The Loop”?
- My add_action (wp_footer, ‘method’) is not calling?
- How to return loop contents
- Hook/action after WP_Query gets posts to query custom tables for post-related meta
- Using the Loop to show all levels of subpages under a parent page? Halfway there
- What is the earliest possible hook for safely using `is_front_page`?
- Cleanest Way to Select Every Second Element in a Loop?
- 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
- Unregister post type from child theme
- Insert image or ad script after 3 posts using the loop
- Get date of last update outside of loop
- Pagination not working on home page
- Child Pages Loop
- How to place comments_template(); outside the loop?
- How do you use the plugin boilerplate loader class to hook actions and filters?
- Add action hook conditionally – only when home.php in use
- How to check if which hook triggered the call to a function?
- Show modified time if post is actually modified
- Multiple Loops Homepage?
- Send data to 3rd party api with wp_remote_post on wp_login
- is it possible to get the hook name in add_action?
- Is there an action for when permalinks are rebuilt?
- How can I log a user out of WordPress before the page loads?
- How to Change Loop to Order Posts by Views (using wp-postviews plugin)
- Check php version before theme activation
- How Do I Load My Action Earlier Enough?
- What is the ‘admin_action_’ . $_REQUEST[‘action’] hook used for?
- how to upload image using wp_handle_upload
- flush_rewrite_rules on save_post Does Not Work on First Post Save