Select2 in WordPress

It’s not. They may have been planning it for 4.1 or 4.2, as suggested in your link, but for whatever reason it never happened. You can see a list of core-registered scripts that you include here. Another thing to keep in mind is that many (arguably too many) plugins enqueue their own version of the … Read more

WordPress Script Loading/Unloading — wp_deregister_script(‘jquery’)

WordPress has essentially two groups of methods to handle scripts, both of which should be used: wp_register_script Registers a script in WordPress. It does not get called, it is just available for WordPress, if it is needed. wp_deregister_script is the exact opposite. It deletes the definitions made in wp_register_script, the script is no longer available … Read more

Why Allow Script Commands in Comments?

It is not “security risk” per se, as an admin can just go and add whatever stupid PHP code it likes via FTP which usually can do much more damage than some JS. If an admin does stupid things then there is nothing you should do about it as after all it is his site. … Read more

How to remove some external js files from source?

You can use wp_dequeue_script to achieve this assuming they are using wp_enqueue_script to add the scripts in the first place. Learn more about enquene and dequeue: https://developer.wordpress.org/reference/functions/wp_enqueue_script/ https://codex.wordpress.org/Function_Reference/wp_dequeue_script function dequeue_script() { wp_dequeue_script( ‘http://buhehe.de/wp-content/themes/heatt/js/small-menu.js?ver=4.9.1’ ); wp_dequeue_script( ‘http://buhehe.de/wp-includes/js/wp-embed.min.js?ver=4.9.1’ ); } add_action( ‘wp_print_scripts’, ‘dequeue_script’, 100 );

Styles and Scripts, Selectively enqueue across entire site

Right I figured this out myself not sure how “hacky” this is but basically this is the code: public function filter_scripts_styles(){ if(is_page($this->plugin_name)){ //Same name is used for the style as the js file so can reuse this array $allowed = array(‘jquery’, $this->plugin_name.’_scrollpath’, $this->plugin_name); //Check Scripts First global $wp_scripts; foreach($wp_scripts->queue as $handle ) { if(!in_array($handle, $allowed)){ … Read more

How do I enqueue(or delay loading of) tags in individual page posts?

General answer: you can call wp_enqueue_script() directly inline in the template, as of WordPress 3.4 (IIRC). So, if you have: <script src=”https://wordpress.stackexchange.com/questions/82668/myscriptforthispageonly.js”></script> You could replace it with: <?php wp_enqueue_script( ‘this-page-script’, get_template_directory_uri() . ‘/myscriptforthispageonly.js’, array( ‘jquery’ ), null, true ); ?> Edit From this comment: This is from within a page. As in a WordPress page. … Read more

How do I load custom scripts and styles for a page?

Yes, you may add conditional tags to the wp_enqueue_scripts action. See the examples below: function load_assets() { wp_enqueue_style( ‘styles’, get_template_directory_uri() . ‘/css/styles.css’); // loads on any ‘page’ post type if( is_page() ){ wp_enqueue_script(‘main-js’, get_template_directory_uri() . ‘/js/main.js’); } // only loads on the page with a slug of ‘home’ if( is_page(‘home’) ){ wp_enqueue_script(‘home-js’, get_template_directory_uri() . ‘/js/home.js’); … Read more