views:

246

answers:

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?

A: 

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');
Richard M
A: 

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.

Jens Törnell