Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load Visual Composer on Every Page (AJAX Setup)

I am using a custom WordPress theme that uses AJAX to load pages. As you can imagine this can create an instance where the site loads to a page that does not use Visual Composer (VC) and then part loads another page that does us VC, since the ready load didn't require the resources.

So far the only solutions I've thought of are using VC on every page (that doesn't work so great for Posts and custom post types) or adding a VC page to the footer (untested).

I looked deeper into the plugins code and found wp_enqueue_script() is called across many files from what looks to be logic calling the correct extension/add-ons to VC as needed, make perfect sense.

My though is that it would be possible to use PHP to solve this issue, to call just the core requirements of VC, since no galleries or anything special will be used.

Does anyone know how to force VC to load resources to every page or have any experience with this? Thank you!

like image 919
Mark Avatar asked Dec 25 '22 11:12

Mark


2 Answers

From what you had said I realised that this needed to be called:

wp_enqueue_script( 'wpb_composer_front_js' );
wp_enqueue_style( 'js_composer_front' );
wp_enqueue_style( 'js_composer_custom_css' );

So I ended up adding something like this in functions.php in my template:

add_action( 'wp_enqueue_scripts', 'add_theme_stylesheet' );

function add_theme_stylesheet() {
    wp_enqueue_script( 'wpb_composer_front_js' );
    wp_enqueue_style( 'js_composer_front' );
    wp_enqueue_style( 'js_composer_custom_css' );
}
like image 65
Mark Aroni Avatar answered Dec 28 '22 10:12

Mark Aroni


WPbakery (authors of VC) explained how to do this.

You have to call a bunch of VC functions in your theme's function file, but couldn't say with absolute certainty.

I haven't tried this method (I'm using Mark Aroni's method above, because I don't need ALL VC stuff on every page, just the CSS/JS), but here's what they say...

vc_twitterBehaviour();
vc_toggleBehaviour();
vc_tabsBehaviour();
vc_accordionBehaviour();
vc_teaserGrid();
vc_carouselBehaviour();
vc_slidersBehaviour();
vc_prettyPhoto();
vc_googleplus();
vc_pinterest();
like image 45
TJ Kelly Avatar answered Dec 28 '22 11:12

TJ Kelly