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');
}