Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Visual Composer

Tags:

php

wordpress

Is there a way to detect if a WordPress page is using Visual Composer?

I have 2 different page templates:

  1. Default template for regular pages.
  2. Template for visual composer pages.

I'm hoping there is a way to detect if a user is using visual composer to build the page instead of relying on the user selecting the visual composer template each time.

Is there a way to detect what page is being built and then assign a template based on that?

like image 496
CreativelyCoded Avatar asked Mar 28 '15 00:03

CreativelyCoded


3 Answers

Yes, you can detect if visual composer is enabled for a post. It's stored in the _wpb_vc_js_status post meta attribute.

$vc_enabled = get_post_meta($post_id, '_wpb_vc_js_status', true);

Note that a post can still contain the visual composer shortcodes, even when visual composer editing is not currently enabled. For example, if I setup a page with visual composer and then revert back to the normal editor, _wpb_vc_js_status will be false.

like image 108
Mathew Tinsley Avatar answered Oct 15 '22 23:10

Mathew Tinsley


only for WPBakery Page Builder

Actually, _wpb_vc_js_status since 4.8 is not correct, because it was not used anymore. The simplest way to check if page is using wpbakery - it is check for vc_row shortcode in content.

$post = get_post();
if ( $post && preg_match( '/vc_row/', $post->post_content ) ) {
    // Visual composer works on current page/post
}
like image 12
Павел Иванов Avatar answered Oct 16 '22 00:10

Павел Иванов


You can detect with is_plugin_active:

if ( is_plugin_active( 'js_composer/js_composer.php' ) ) {
     //your code here
}
like image 3
Pan Bouradas Avatar answered Oct 16 '22 00:10

Pan Bouradas