You can’t remove the line of code, but do_action() runs all the actions that have been added by add_action() for that tag.
You can use a function in functions.php to remove one or more actions assigned to a tag.
The ‘template_redirect’ tag has several default actions, but the one I think most likely to cause problems is the ‘maybe_redirect_404’ action.
I cannot test this right now, but please give it a try. Add this to functions.php:
function remove_action_template_redirect() {
remove_action('template_redirect','maybe_redirect_404');
}
add_action('wp_loaded','remove_action_template_redirect');
If that does not work, I will provide code to remove the other actions.
hi vtxyzzy,
pardon the delay, I had to step away from this but I am back on the case. I tried the remove action described above but it did not work. Can you provide the other code to remove other actions?
Also as a more general wordpress question, going forward if I want to see the actions associated with a particular tag I should be able to look at the core file that contains the tag and find the actions within there, correct?
Thanks again for all your help!
Here are all the references I found in wp-includes:
./canonical.php:452:add_action('template_redirect', 'redirect_canonical');
./default-filters.php:214:add_action( 'template_redirect', 'wp_shortlink_header', 11, 0 );
./default-filters.php:272:add_action( 'template_redirect', 'wp_old_slug_redirect' );
./ms-default-filters.php:32:add_action( 'template_redirect', 'maybe_redirect_404' );
Remove them all to see if that solves your problem. Note that wp_shortlink_header has a priority and option count that must be the same in the remove_action().
If that fixes the problem, you should remove them one at a time to find the one(s) actually causing the problem.
Thanks for the response vtxyzzy.
I want to verify I understand the syntax to implement this with you. To remove these actions should I put the code below in functions.php?
function remove_action_template_redirect() {
remove_action('template_redirect','redirect_canonical');
}
add_action('wp_loaded','remove_action_template_redirect');
and
function remove_action_template_redirect() {
remove_action( 'template_redirect', 'wp_shortlink_header', 11, 0 );
}
add_action( 'template_redirect', template_redirect' );
and
function remove_action_template_redirect() {
remove_action( 'template_redirect', 'maybe_redirect_404' );
}
add_action('wp_loaded','remove_action_template_redirect');
and
function remove_action_template_redirect() {
remove_action( 'template_redirect', 'wp_old_slug_redirect' );
}
add_action('wp_loaded','remove_action_template_redirect');
Thanks!
You should put all your ‘remove_action()’ calls in one function:
function remove_action_template_redirect() {
remove_action('template_redirect','redirect_canonical');
remove_action( 'template_redirect', 'wp_shortlink_header', 10, 0);
remove_action( 'template_redirect', 'maybe_redirect_404' );
remove_action( 'template_redirect', 'wp_old_slug_redirect');
}
add_action('wp_loaded','remove_action_template_redirect');
Thanks, that makes more sense π
Nope none of these did the trick :/ I am not sure why removing that line of code mentioned in the beginning of this thread worked, and why removing actions did not work, very odd…
Perhaps there is an ‘template_redirect’ action that is not in wp_includes.
There is a way to see all the actions for a given tag, but I don’t remember what it is right now. I think it involves declaring a global for the action array and displaying it.
Ok I’ll look that up and see if I can figure out the way to do that. Sounds like that’d be a helpful trick to know for the wordpress toolkit :).
actually as I was researching I found something in the codex that I think might actually be the exact fix I was looking for all along.
“remove_all_actions” Removes all of the hooks from an action.
http://codex.wordpress.org/Function_Reference/remove_all_actions
I just ran remove_all_actions on ‘template redirect’ and it worked like a charm.
Do you have any thoughts here? Unless there is a reason not to use this, I think we can consider this fixed :).
Since I really don’t know what all the actions are doing, I can’t say if there is any reason to avoid using remove_all_actions().
right… since commenting out the template redirect tag fixed my original problem with no negative side effects and i am looking for a way to do that through functions.php removing all the actions associated that tag i am imagining does the same effect. since there seem to be no negative side effects with this what i was looking to accomplish seems to have been found.
i appreciate your time and energy and am thankful for you assistance :). have a great one!
If your problem has been solved, please use the dropdown on the right to mark this topic ‘Resolved’ so that anyone else with this question can see that there is a solution.