1

I'm trying to remove the head meta added by VC, namely "meta name="generator" content="Powered by Visual Composer - drag and drop page builder for WordPress".

If I add:

add_action('init', 'myoverride', 100);
function myoverride() {
    remove_action('wp_head', array(visual_composer(), 'addMetaData'));
}

it works and removes it. But what I want is to remove it IF installed, because if it isn't the above code throws an error obviously.

If I add:

if ( class_exists( 'Vc_Manager' ) ) {
add_action('init', 'myoverride', 100);
function myoverride() {
    remove_action('wp_head', array(visual_composer(), 'addMetaData'));
}
}

it doesn't work at all. I've checked the class name and it is correct. I'm a PHP noob so any advice is appreciated.

1 Answer 1

1

your problem boils down to doing things before the init hook was fired. You should never check for code existence, DB structure before it. In case of frontend related code you should not do anything before template_redirect hook.

Your code should be like

add_action('wp_head', 'myoverride', 1);
function myoverride() {
  if ( class_exists( 'Vc_Manager' ) ) {
    remove_action('wp_head', array(visual_composer(), 'addMetaData'));
  }
}
3
  • +1 for using wp_head action hook. However, it's probably better to check for function_exists( 'visual_composer' ) instead of class_exists( 'Vc_Manager' ). That way it'll work even if they change the class name in the future. On the other hand, if they change the function name, the remove_action will not work anyway.
    – Fayaz
    Commented Feb 19, 2017 at 10:59
  • Having said that, I've never used VC, so I don't know if the function visual_composer comes built in with VC or just a theme function. Hence I said "probably better".
    – Fayaz
    Commented Feb 19, 2017 at 11:04
  • for me both methods are not reliable, and better to jusr not use a pluin that think that it can use your site for its own advertisement, but I never truly understand why anyone that can write php code like the OP demonstrates will even think about using a page builder. Commented Feb 19, 2017 at 12:38

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.