How to Add a .js file Only in one specific Page Dynamically to Head

Use conditional is_page() for loading script on specific page. Here Is The Modified Version of Your Function: //Load Scripts function load_scripts(){ wp_deregister_script(‘jquery’); // De-register Existing jquery wp_register_script(‘jquery’, ‘http://code.jquery.com/jquery.js’, ”, ”, true); wp_enqueue_script( ‘jquery’ ); wp_register_script(‘bootstrap-jquery’,get_template_directory_uri().’/assets/js/bootstrap.js’, array( ‘jquery’ ), ”, true); wp_enqueue_script( ‘bootstrap-jquery’ ); // register the script wp_register_script( ‘my-script’, ‘URL to Script’ ); // by … Read more

What does “Do not deregister the jquery script in the administration area” mean?

Based on the error… add_action( ‘wp_enqueue_scripts’, function(){ if (is_admin()) return; // don’t dequeue on the backend wp_deregister_script( ‘jquery’ ); wp_register_script( ‘jquery’, ‘http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js’, array(), null, false ); wp_enqueue_script( ‘jquery’); }); Honestly, unless you have tremendous traffic over a broad geographic area, I’d say that CDNs are grossly over-rated. I’ve watched the hangup on sites I’ve managed … Read more

Where do I find the functions triggered within a hook?

Looking at the current version of Storefront’s header.php: /** * Functions hooked into storefront_header action * * @hooked storefront_skip_links – 0 * @hooked storefront_social_icons – 10 * @hooked storefront_site_branding – 20 * @hooked storefront_secondary_navigation – 30 * @hooked storefront_product_search – 40 * @hooked storefront_primary_navigation_wrapper – 42 * @hooked storefront_primary_navigation – 50 * @hooked storefront_header_cart – … Read more

Conditionally loading JavaScript based on the Advanced Custom Fields in the post

ACF has finegrained filters for fields when they get loaded. add_action( ‘wp_enqueue_scripts’, ‘register_my_scripts’, 5 ); function register_my_scripts() { wp_register_script( ‘my-script’, ‘path-to/my-script.js’, array(), ‘version’, true ); } add_filter(‘acf/load_field/name=my_field_name’, ‘load_field_my_field_name’); function load_field_my_field_name( $field ) { wp_enqueue_script( ‘my-script’ ); return $field; } Normally all scripts should be enqueued in wp_enqueue_scripts hook. So you should make sure your script … Read more

How to develop a multilingual theme?

Daniel’s answer was very similar, but applied to plugins rather than themes. For that reason I’ll explain how I specifically did it for themes for anyone else who comes across this problem. Create a folder in the root of your theme called “languages” Go to https://wpcentral.io/internationalization/, search for your language and copy the “WordPress Locale” … Read more

Add a notice to users upon first login to the admin area

something like: add_action(‘admin_notices’, ‘my_notice’); add_action(‘wp_ajax_hide_my_notice’, ‘hide_my_notice’); function hide_my_notice(){ check_ajax_referer(‘hide-my-notice’); $user = wp_get_current_user(); // update status for this user $seen_notice = get_option(‘my_notice’); $seen_notice[$user->ID] = true; update_option(‘my_notice’, $seen_notice); exit; } function my_notice(){ $user = wp_get_current_user(); $seen_notice = get_option(‘my_notice’); // already seen it? if(isset($seen_notice[$user->ID]) && $seen_notice[$user->ID]) return; ?> <div class=”updated fade below-h2″> <p> Hi <?php print esc_attr($user->user_login); ?>! … Read more