Moderator
Jan Dembowski
(@jdembowski)
Forum Moderator and Brute Squad
Moved to Fixing WordPress, this is not a Developing with WordPress topic. This is a theme specific topic not a developing one.
Screenshots of code samples are the worst way to ask for support. It doesn’t help you or anyone when you do that. Try sharing the code samples using https://pastebin.com/ instead.
Which theme is that and where did you download it from? If you can provide that information then it will help get you to the right place.
Wordpress defaults to a jQuery version where usage of $ is not defined. So you need either add that to your script yourself or replace all calls to jQuery functions by changing $(…) to jQuery(…).
@superkot I have replace the $ by jQuery, but still nothing happens
@jdembowski The theme I’m using is WP Bootstrap StarterVersie: 3.1.0, which is to be found on the WP Repository.
My code in functions.php: https://pastebin.com/P2Ew7hmT
My code in script.js: https://pastebin.com/SeYR8mRB
Your script is ok if you execute is by pasting in console, so the problem is with enqueueing. Why would you use array(‘javascript’)? Your dependency is jQuery. Anyway, try simplier first:
wp_enqueue_script( 'myscript', get_template_directory_uri() . '/js/script.js', array('jquery') );
Hi Superkot, I tried your code but no result. I also tried to paste my jQuery code in the console, but still nothing.
You must be doing something wrong. Your code works perfectly fine for me, you just need to enqueue it properly. Copypasting script video: https://cloud.mail.ru/public/2Wjm/5gRDms6xp. Anyway, if you fail to enqueue it as separate file, you can simply add this script to your footer, its not big so it wont affect your site performance.