Friday, 15 February 2013

php - Wordpress plugin cpage variable -



php - Wordpress plugin cpage variable -

i making plugin hide canonical element header on comment pages.

my finish plugin code is:

global $cpage; if($cpage > 1){ remove_action('wp_head', 'rel_canonical'); }

so if comment page number > 1 remove canonical.

if have remove_action('wp_head', 'rel_canonical'); without if works...but trying utilize variable $cpage (which gives comment page number in wordpress) remove on comment pages...

what doing wrong here?

try:

function kill_comments_canonical() { global $cpage; if(!empty($cpage) && $cpage > 1){ remove_action('wp_head', 'rel_canonical'); } } add_action('wp_head','kill_comments_canonical',9);

you have several problems original code. first, $cpage may not set when need be-- when code in plugin runs, hook wp_head when set. secondly, need run remove_action after rel_canonical added before prints, hence 3rd priority parameter in add_action on lastly line. came number via trail , error, way.

php wordpress wordpress-plugin

No comments:

Post a Comment