开发者

Load jquery plugin in a custom wordpress widget

开发者 https://www.devze.com 2022-12-21 14:04 出处:网络
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 ac

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' );
   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号