Articles of scripts

WordPress doesn't Load JQuery Now? Do I need to enqueue JQuery also?

In my HTML I was loading JQuery, but I am not loading it when converting HTML into the WordPress. because I think WP automatically loads it. However there is a custom.js sitting in the js folder, and I am trying to load it like this → if ( ! function_exists( ‘puck_scripts’ ) ) { function […]

Load plugin scripts and styles only on plugin page

Hello wordpress users, I’m stuck with a problem while running 2 self made WordPress plugins. I’ll use the following code : define(‘PLUGIN_URL’, plugin_dir_url( __FILE__ )); add_action( ‘admin_enqueue_scripts’, ‘plugin_load_js_and_css’ ); function plugin_load_js_and_css() { wp_register_style( ‘plugin.css’, PLUGIN_URL . ‘plugin.css’, array()); wp_enqueue_style( ‘plugin.css’); wp_register_script( ‘plugin.js’, PLUGIN_URL . ‘plugin.js’, array(‘jquery’)); wp_enqueue_script( ‘plugin.js’ ); } } But it’s loading this […]

How to cancel `wp_print_scripts`?

I want to load all the scripts in $wp_scripts with my own JS function after the window.onload event. Is there a simple way to prevent wp_print_scripts from printing the default list of <script> tags so I can replace it with my own code?

wp_register_script multiple identifiers?

In order to avoid poor performance with multiple <script> tags I do concatenation of scripts regularly and produce one single bundle.min.js JS file and ‘jsbundle’ identifier. Problem is, things added subsequently, like plugins, may depend on registered one or more libraries that are present, but packed in generic ‘jsbundle’. Is there a way to inform […]

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

Different pages often need different set of scripts and styles for them. I use functions.php and construction like this to load scripts and styles: function load_assets() { wp_enqueue_style( ‘styles’, get_template_directory_uri() . ‘/css/styles.css’); wp_enqueue_script(‘main-js’, get_template_directory_uri() . ‘/js/main.js’); } add_action( ‘wp_enqueue_scripts’, ‘load_assets’ ); I know I can put some condition here like this: is_page() but is there […]

How can I selectively print scripts to the footer of certain admin pages?

I’m using admin_footer-{$hook_suffix} to selectively print scripts on the new post page and comments page. This hook is depreciated in 3.1. I see there’s an admin_print_scripts-{$hook_suffix} but this does not print to the footer, rather to the header before any jQuery or other stuff is loaded. How can I selectively print scripts to the footer […]

Question about the way that wp_register_script works

Ok so I’m using the Roots Theme for WordPress (https://github.com/retlehs/roots), which, is sort of a starter theme or theme framework. I’m confused about the way that it deregisters the WordPress loaded version of jQuery and but it registers it again without specifying the exact location of the script. So in the header.php of the theme […]

How do you load WordPress from an external script when using MultiSite?

Possible Duplicate: Using WordPress functions on other sites I have an external script that needs to load up WordPress in order to have access to WordPress functionality. In the past I have successfully done this by including wp-load.php. However, when using MultiSite, this does not work. It appears to be logged as a bug here. […]

Serving wp-includes (front-end) javascript from a different domain?

The WordPress Codex points to an extremely simple way to change the URL of the wp-content directory, which is, adding this in wp-config.php: define( ‘WP_CONTENT_URL’, ‘http://example.com/wp-content’); And that does the job of serving most of the JavaScript and CSS files on my website from the different domain, except two. http://mywebsite.com/wp-includes/js/comment-reply.js http://mywebsite.com/wp-includes/js/quicktags.js The reason is very […]

How to properly add Bootstrap and JQuery Javascripts?

I am developing my WordPress theme using Material Bootstrap Design (MDB), a Material variant that uses Bootstrap 4 plus its own code. It calls for using the following scripts… <!– JQuery –> <script type=”text/javascript” src=”/wp-content/themes/blankslate/mdb/js/jquery-2.2.3.min.js”></script> <!– Bootstrap tooltips –> <script type=”text/javascript” src=”/wp-content/themes/blankslate/mdb/js/tether.min.js”></script> <!– Bootstrap core JavaScript –> <script type=”text/javascript” src=”/wp-content/themes/blankslate/mdb/js/bootstrap.min.js”></script> <!– MDB core JavaScript –> […]