wp_enqueue_script was called incorrectly
And an additional backend error:
The block reblex-widget
has issues.
Object
: "rest_invalid_widget"
This occurs with latest WordPress 5.9
but also with the previous WordPress 5.8.3
release.
wp_enqueue_style( 'theme-css', get_template_directory_uri() . '/custom.css?asaghjgla');
wp_enqueue_script( 'theme-js', get_template_directory_uri() . '/js/theme.js', array(), '19', true );
“?asaghjgla” at the end of the css is literally just me slamming on the keyboard every time, and the “19” with the js is a version number I keep adding to every time I make a js change.
If I don’t do this, purging/clearing the cache doesn’t do anything, and my changes don’t show up. To avoid having to manually do this every time, I tried creating a PHP function, and it didn’t work as planned.
I also read somewhere to change define( 'WP_CACHE', TRUE );
to false
in the wp-config file, and that didn’t do anything.
Is this something new with the new version of WordPress that I need to keep updating this every single time? How do I fix it so I don’t have to do this every time? It’s driving me insane.
]]>You should edit the Widget.php file (located in lib / config) to declare script dependencies (jQuery in this case).
line 105 should be as follows:
wp_enqueue_script(
'mailpoet_public',
Env::$assets_url . '/js/' . $this->renderer->getJsAsset('public.js'),
array('jquery'), // add dependencies
Env::$version,
true
);
]]>wp_enqueue_script( 'flexslider' , get_template_directory_uri() . '/js/jquery.flexslider.js', array('jquery'), '1', true);
The scripts work, but Google pagespeed insights says I should load these files in the footer. I understood that setting that last parameter to ‘true’ did exactly that! But when I check the page source I see these scripts are in fact loading in the header.
Is there something wrong with the wp_enqueue_script above? Or should I look somewhere else for the solution?
]]>I have been trying to add a scriptto my site that depends on jquery, but I can’t get it to work. Any help would be much appreciated. Thank you.
Here’s what I have in my functions.php:
/*Adds accordion script*/
function accordion_script(){
wp_register_script('accordion', get_template_directory_uri() . 'https://kubetest.kube.co.uk/wp-includes/js/accordion-script.js', 'jquery');
wp_enqueue_script('accordion');
}
add_action( 'wp_enqueue_scripts', 'accordion_script');
Here is the contents of accordion-script.js:
$j(document).ready(function(){
var $j = jQuery.noConflict();
$j(function($) {
var allPanels = $j('.post-list > li > .entry-summary').hide();
$j('.post-list > li').click(function() {
allPanels.slideUp();
$j(this).parent().next().slideDown();
return false;
});
})(jQuery);
});
]]>function addMyScripts()
{
wp_register_script(
'clever-dl',
get_template_directory_uri() . '/js/clever-dl.js',
array( 'jquery' ),
'20101009.5',
true
);
wp_enqueue_script( 'clever-dl' );
}
add_action( 'wp_enqueue_scripts', 'addMyScripts' );
The page seems to render fine, with the right paths to the right scripts in the right places, but Firebug is telling me that jquery is not found when it tries to run my JS. =8-0
Any suggestions? Thanks in advance for any help!
]]>I can get ‘admin_print_scripts-‘ to work.
add_action( 'admin_print_scripts-media.php', array( &$ELLGmapKML, 'kml_print_admin_scripts' ) );
add_action( 'admin_print_scripts-media-upload.php', array( &$ELLGmapKML, 'kml_print_admin_scripts' ) );
The first one works- ie scripts are added to the media.php page, but not with the 2nd hook- scripts are not added to the media-upload.php page. Is there another way to make this work? I’ve tried using wp_print_scripts and wp_enqueue_script to try and actually insert the scripts, but neither works.
Any tips, anyone?
a|x
]]>wp_enqueue_script
to add the scripts to the head or footer of each page (by ‘page’, I mean page of content, not specifically a WordPress Page).
However, this means that the scripts will be called for every page, even if none of the posts on the page require the script. I’m wondering if it’s a good idea to use an iFrame for the inserted content, and have the embedded page call the script. That way, the script is only called when required. I can’t see any practical disadvantages at the moment, but I’d be very surprised if somebody else hadn’t thought of (and probably dismissed) this. I’d be very interested to know if anyone has any thoughts on the advantages or disadvantages of using this method over the enqueue_script one.
Cheers,
a|x
]]>Is it possible to load the js in wp_head
only for home or index only? I tried is_home() and is_front_page() but still doesn’t work.
I also tried adding the <?php wp_reset_query(); ?> and it doesn’t work either.
By the way, I’m using the add_action event: add_action('wp_enqueue_scripts', 'my_enqueue_scripts');
Does anyone guys there have an idea on how to accomplish this?
Any help would be much appreciated.
Thanks in advance.
]]>