Only load style/js when shortcode is used
-
Current code loads most of the files on every page
But I don’t see any side effect from moving everything inside the “if used”
<?php // attachment.php //wp_enqueue_script( 'jquery' ); if ( wpuf_has_shortcode( 'wpuf_addpost' ) || wpuf_has_shortcode( 'wpuf_edit' ) ) { wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'plupload-handlers' ); wp_enqueue_script( 'jquery-ui-sortable' ); wp_enqueue_script( 'wpuf_attachment', plugins_url( 'js/attachment.js', dirname( __FILE__ ) ), array('jquery') ); } //wp_enqueue_script( 'jquery-ui-sortable' ); //wp_enqueue_script( 'wpuf_attachment', plugins_url( 'js/attachment.js', dirname( __FILE__ ) ), array('jquery') ); //index.php //wp_enqueue_style( 'wpuf', $path . '/css/wpuf.css' ); if ( wpuf_has_shortcode( 'wpuf_addpost' ) || wpuf_has_shortcode( 'wpuf_edit' ) ) { wp_enqueue_style( 'wpuf', $path . '/css/wpuf.css' ); wp_enqueue_script( 'plupload-handlers' ); wp_enqueue_script( 'wpuf', $path . '/js/wpuf.js', array('jquery') ); } //wp_enqueue_script( 'wpuf', $path . '/js/wpuf.js', array('jquery') );
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Only load style/js when shortcode is used’ is closed to new replies.