Im trying to make a wordpress widget containing a jquery photo gallery. The widget will only be on a few pages on the site, so I would like to only load the jquery gallery plugin when the widget is actually shown. Any ideas on how to do that? Im thinking I need to throw in a wp_enqueue_script in my widget function somewhere, but wher开发者_StackOverflow社区e?
Add jquery using wp_enqueue_script. You can then deregister that script for all pages except for where you are going to use the widget. Note that this may introduce problems for future plugins that uses jquery!
add_action( 'wp_print_scripts', 'deregister_jquery', 100 );
function deregister_jquery() {
if ( !is_page(array(2,'one page','another page')) ) {
wp_deregister_script( 'jquery-js' );
}
}
精彩评论