Articles of wp enqueue script

Best way to enqueue extremely popular scripts like bootstrap and font awesome

Scripts and Styles like bootstrap and font awesome are used on hundreds/thousands of plugins. Whats the best way to check for this? If two scripts aren’t registered with exact same name they’ll both get loaded. This is most frustrating when a plugin includes font-icons from ico-moon or somewhere similar that change the icon codes so […]

Problem enqueuing scripts on not single posts

I have this code to enqueue a script file when the page is not single.php (neither admin page): //functions.php /********************** Add JS file **************************/ function my_own_scripts() { if (! is_admin() && ! is_single()) { wp_register_script( ‘my_javascript_file’,get_bloginfo(‘stylesheet_directory’) . ‘/js/my_javascript_file.js’, array( ‘jquery’ ) ); wp_enqueue_script( ‘my_javascript_file’ ); } } add_action( ‘wp_enqueue_scripts’, ‘my_own_scripts’ ); But the script is […]

Calling wp_localize_script in a different function

I am trying to localize a variable in a javascript below.. The scenario is that I want to dynamically get the post_id and localize it in the jquery I have enqueued through wp_enqueue_scripts. Here’s my code: function add_scripts() { wp_enqueue_style(‘jplayercss’,plugins_url( ‘skin/’,__FILE__)); wp_enqueue_script( ‘jplayer’,plugins_url( ‘js/jquery.jplayer.min.js’ , __FILE__ ) ); wp_enqueue_script( ‘jplayerjs’,plugins_url( ‘js/mfsjplayer.js’,__FILE__), array(‘jquery’) ); } add_action( […]

Understanding wp_enqueue_style

I am trying to understand how wordpress works, but I am having issue understanding how wp_enqueue_style(), wp_enqueue_script() works in relation to page output. From my understanding, these functions do not output anything to the page until the template have been loaded because the template might want to register a style/script. Going through wordpress themes files, […]

Proper enqueue for child theme functions.php

I didn’t set up a child theme to start off with, so now I’m trying to do that. I do have the child theme active. I read over this POST and still cannot get my child theme style.css to hook before anything else. I’m not well versed with coding and not sure how to write […]

Enqueueing TinyMCE

I have decided to pull duplicated javascript from multiple custom post type files into one ‘admin.min.js’ file for use in all admin pages. So far I have got the script to load. This is in my scripts.php (I use Roots theme) // Add the admin css function custom_admin_style(){ wp_register_style(‘admin_css’, get_template_directory_uri() . ‘/assets/css/admin.min.css’); wp_register_script(‘admin_js’, get_template_directory_uri() . […]

Why does deregistering jQuery cause other scripts not to load?

I’ve inherited a site using the following in functions.php: if ( ! function_exists( ‘foundation_assets’ ) ) : function foundation_assets() { if (!is_admin()) { wp_deregister_script(‘jquery’); } wp_enqueue_script( ‘new-slider’, get_template_directory_uri() . ‘/scripts/new.Slider.js’, array(), NULL, true ); } add_action( ‘wp_enqueue_scripts’, ‘foundation_assets’ ); endif; If I prevent this function from running, other plugins load additional scripts correctly. Has the […]

How to create a child theme with multiple css files.

Noob at wordpress development. Trying to create a child theme for a client. But the problem is that there are many css files and not one as per many tut’s available, in my senario there are multiple css files. Can somebody help me in giving high level overview of how to create a child theme.

How to load script conditionally on custom field in wp_postmeta?

I’m trying to tidy up some of the code that has been doing its job for quite a while. Specifically, I used to load scripts in header.php and I’m trying to move that into functions.php. One of the scripts should be loaded only for pages with a certain value in wp_postmeta. Precisely, if and only […]

Enqueueing Scripts and Styles to page template that has html

I built a custom calculator using html5, css3, and jQuery. I have it live and it works well but now someone would like to put my calc on their WP website and we can not figure out how to get it on his WP site. I created a calculator.php page template and put my .html […]