admin管理员组

文章数量:1279055

I am trying to manually use the accordion tool from wpbakery. Now before my question gets closed, my question is not about wpbakery.

My question is how to load the correct scripts so that the accordion will work without actually using an accordion function in the page edit screen.

If editing a page and I add my short code (which adds HTML similar to the output that would be made if I added an accordion option from the wp-bakery edit screen), then on the front end that page doesn't present the accordion function correctly. however if i add an accordion from my edit screen, then both the accordion and my shortcode output accordions on the front and both work perfectly.

I think it is because wp-bakery has a function that says "if you are using our accordion option, enqueue our js".

I had verified this by checking that this script is loaded when I add an accordion properly:

<script type='text/javascript' src='.min.js?ver=6.7.0' id='vc_accordion_script-js'></script>

is loaded, but otherwise it's not.

So I tried adding this code to functions.php:

function enqueue_scripts_style_page_content_using_shortcode(){
        wp_enqueue_script('vc_accordion_script-js');
}
add_action( 'wp_enqueue_scripts', 'enqueue_scripts_only_if_page_using_shortcode' );

as well as

function enqueue_scripts_style_page_content_using_shortcode(){
        wp_enqueue_script('vc_accordion_script-js', '.min.js');
}
add_action( 'wp_enqueue_scripts', 'enqueue_scripts_only_if_page_using_shortcode' );

However, neither load the script.

So my question is how to make sure this script is loaded even if I don't actually use the accordion widget from the plugin?

本文标签: How can I manually enqueue plugin scripts