Tag Info

New answers tagged

0

Here is a working example for Wordpress 4.2 and above. This first example was previously answered here. wp_enqueue_script("ie_jshandle", get_template_directory_uri() . "/js/jsSpecificIE.js", array(), '1.0', false ); wp_enqueue_script("ie_jshandle"); ...


0

Ok, I figured it out: If it's a submenu page, the $hook looks like this: appearance_page_page-name instead of going by URL. So the complete code would be this: function my_function($hook) { if ( 'appearance_page_page-name' != $hook ) { return; } wp_enqueue_style( 'custom-style', get_template_directory_uri() . 'custom-page/style.css' ); } ...


0

if you have declared the page with add_theme_page(..., you can add the stylesheet in the hook load-appearance_page_page-name or admin_print_styles-appearance_page_page-name. for information, these are some hook which are fired when you load the page (it's not the whole list but the most interesting for your question) plugins_loaded init admin_init ...


1

The earliest safe hook to get post information is the template_redirect hook. All the hooks in question runs before Wordpress has setup postdata, so any post info are still unavailable at that point. The globals like $wp_query and $post will still contain no data, that is why your efforts returns nothing. EDIT Extra info as per comment by @TheDeadMedic ...


0

Seems like you need to add __ before your variable value, try this code: wp_localize_script('itenqueue', 'itajax', array( 'ajaxurl' => __('hi there') )


0

For using require JS you need add in head <!-- Delayed execution of inline jQuery scripts with ready waiting event --> <script type="text/javascript">(function(w, d, u){w.readyQ = []; w.bindReadyQ = []; function p(x, y){if (x == "ready"){w.bindReadyQ.push(y); } else{w.readyQ.push(x); }}; var a = {ready:p, bind:p}; w.$ = w.jQuery = function(f){if ...


1

Prioritize your actions, so the register_style function runs first. (notice the third parameter in the add_action function) add_action( 'wp_enqueue_scripts', 'other_register_styles', 11 ); function other_register_styles() { wp_register_style( 'style', PATH . 'assets/css/style.min.css' ); wp_enqueue_style( 'style' ); // Working as expected ...


0

In the context of parent - child themes, be aware that: The get_template_directory_uri() will give you the parent theme directory uri: https://codex.wordpress.org/Function_Reference/get_template_directory_uri. The get_stylesheet_directory_uri() will give you the child theme directory uri: ...


1

This is how you would use the user_register hook to load your script: add_action( 'user_register', 'new_user_tracking_script' ) function new_user_tracking_script(){ // Google Analytics wp_enqueue_script( 'new_user_tracking' ); }


1

The "Failed to load resource" is probably a red herring and isn't related to your issue. The fact that it is throwing an error about the $ shortcut means your js file is being loaded correctly. The likely issue is that jQuery in WordPress loads in "noConflict" mode. As such the $ shortcut will not work by default. Try replacing your script with this: ...



Top 50 recent answers are included