2

I need to do this for a theme:

remove_action( 'wp_head', 'rel_canonical' );

BUT I need to do that with conditional tags. The code below don't work.

if(is_page('comment'))
{
   remove_action( 'wp_head', 'rel_canonical' );
}

AND I need to do this with a plugin.

I tried to hook the if statement into the function test, like this:

add_action('init', 'test');
function test()
{
   if(is_page('comment'))
   {
      remove_action( 'wp_head', 'rel_canonical' );
   }
}

Because it is run before anything else the conditional tags don't work, I guess.

Any ideas?

2 Answers 2

4

I found out that instead of using init as an action, I should use this:

add_action('template_redirect', 'test');

Then it runs before the header.php but after the conditional tags are set.

0
1

Try replacing the rel_canonical action with your own function containing the condition, something like this:

remove_action('wp_head', 'rel_canonical');
function my_rel_canonical() {
    if (!is_page('comment')) rel_canonical();
}
add_action('wp_head', 'my_rel_canonical');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.