shortcodes

  • Sensible script enqueuing for shortcodes

    If you are making a WordPress plugin which uses a shortcode, and said shortcode needs some Javascript enqueued in order to function, it may be tempting to just whack the script in the wp_enqueue_scripts hook and be done with it. add_action( ‘wp_enqueue_scripts’, ‘enqueue_my_script’ ); function enqueue_my_script() { wp_enqueue_script( ‘script-name’, plugins_url( ‘/js/script.js’ , __FILE__ ), array(),…