Answer the question
In order to leave comments, you need to log in
*** How to connect the script only if there is a certain shortcode on the page?
To use jquery-ui-accordion you need to add a javascript like this to the page:
jQuery(function($){
$(document).ready(function(){
$( ".office-accordion" ).accordion({heightStyle: "content"});
});
});
Answer the question
In order to leave comments, you need to log in
It is most convenient to make svg, but here, of course, everything depends on what is in these elements.
That's right
function custom_shortcode_scripts() {
global $post;
if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'custom-shortcode') ) {
wp_enqueue_script( 'custom-script');
}
}
add_action( 'wp_enqueue_scripts', 'custom_shortcode_scripts');
jQuery(function($){
$(document).ready(function(){
function test(){
if( ! $( ".office-accordion" ).length ) return false;
$( ".office-accordion" ).accordion({heightStyle: "content"});
}
test();
});
});
And you can in functions.php:
function has_shortcode_func($atts){
$xhtml = '<script type="text/javascript"> jQuery(function($){
jQuery(document).ready(function(){
jQuery( ".office-accordion" ).accordion({heightStyle: "content"});
}); });</script>';
return $xhtml;
}
add_shortcode('has_shortcode', 'has_shortcode_func');
[has_shortcode]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question