Load custom CSS before admin CSS

By default they should already be loading after the core admin styles. I suspect the CSS isn’t even being loaded because you have an invalid parameter in your wp_enqueue_style() call. Its parameters are the same as wp_enqueue_script(). Where you have 99 is where dependencies are actually defined. So WordPress is looking for 99 to be … Read more

Custom plugin – load enqueue only for this plugin

The WordPress documentation for admin_enqueue_scripts says that you can: function load_custom_wp_admin_style($hook) { // Load only on ?page=mypluginname if($hook != ‘toplevel_page_mypluginname’) { return; } wp_enqueue_style( ‘custom_wp_admin_css’, plugins_url(‘admin-style.css’, __FILE__) ); } add_action( ‘admin_enqueue_scripts’, ‘load_custom_wp_admin_style’ ); Basically, you’re being passed $hook and it should be the value of your page name, which is the name you’ve chosen.

enqueing Javascript and CSS

If you care about pagespeed and those standards, you should make the resources local instead of off remote servers. Although they’re all off CDNs, nothing’s faster than local. With http/2 on the rise, its going to become less and less important to have fewer scripts- but having them locally will still matter. You can combine … Read more

how to load css and js based on post template

It looks like your condition check is correct. As per the comments to the question, don’t forget to add it as a callback to the wp_enqueue_scripts action hook. function enqueue_styles_and_scripts() { if ( is_page_template(‘htmlcode.php’) ) { wp_enqueue_style( ‘code-mirror-css’, get_template_directory_uri() . ‘/code-mirror/plugin/codemirror/lib/codemirror.css’, array(), ‘all’); wp_enqueue_style( ‘code-mirror-monokai’, get_template_directory_uri() . ‘/code-mirror/plugin/codemirror/theme/monokai.css’, array(), ‘all’); wp_enqueue_script( ‘code-mirror-js’, get_template_directory_uri() . ‘/code-mirror/plugin/codemirror/lib/codemirror.js’, … Read more

How to enqueue a script which is type module without using script_loader_tag filter?

Lets try this: function slider_script () { wp_enqueue_script( ‘slider-js’, get_stylesheet_directory_uri() . ‘/src/js/slider.js’, array(), time(), true ); } function add_type_attribute( $tag, $handle, $src ) { if ( ‘slider-js’ !== $handle ) { return $tag; } $tag = preg_replace(“/(.*)(><\/script>)/”, ‘$1 type=”module”$2’, $tag); return $tag; } add_action(‘wp_enqueue_scripts’, ‘slider_script’); add_filter( ‘script_loader_tag’, ‘add_type_attribute’, 10, 3 );

Enqueing External JS on the remote server JS

You use $ in custom.js file and probably that’s the reason, because jQuery is included in WordPress in noConflict mode. You can replace $ with jQuery in custom.js or wrap the code as shown below: (function( $ ) { // — your code — $(document).ready(function() { //… }); })(jQuery); Or jQuery(document).ready(function($) { // code from … Read more

Why is WordPress enqueuing admin relevant scripts (e.g., React, ReactDOM, Redux, hooks, TinyMCE etc) when not logged in?

If your bootstrap or other enqueued scripts have a dependency or name conflict, this could enqueue all these scripts. There are a large number of common scripts in WordPress core that are enqueued under common names. I always recommend prefixing your script names with something specific. wp_enqueue_script( ‘theme-bootstrap’, ‘https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js’, array( ‘jquery’ ), ‘4.3.1’, true );