-
AuthorPosts
-
April 27, 2016 at 1:48 pm #623052
hi,
i want to load my own javascript file.
i have a child theme. There i insert the folder “js”.In the folder i put the js file “jongo-js”
than i put the following code to my function.php in my child theme://custom Javascript laden wp_register_script( 'jongo-js', $template_url.'/js/jongo-js.js', 'jquery', "1", true); wp_enqueue_script( 'jongo-js' );
When i look to the source-code of my site i clould find the script. But it links to a 404 error page and not to the javascript. Where is the mistake?
best regards
Chris
April 29, 2016 at 10:38 am #624219ok,
now i can load the javascript to the source-code but it doesnt effect my html classes. when i load it with the codeblock it effects the html classes and all is fine. I dont understand this. Can you help me?
- This reply was modified 8 years, 6 months ago by Chris_85.
April 29, 2016 at 10:47 am #624224Hi!
To register and enqueue your own js files in wordpress please use the following code in functions.php
/* * Custom js */ function my_custom_scripts() { wp_register_script('script_one', plugins_url('custom_script.js', __FILE__), array('jquery'),'1.1', true); wp_enqueue_script('script_one'); } add_action( 'wp_enqueue_scripts', 'my_custom_scripts' );
For more info please check https://developer.wordpress.org/themes/basics/including-css-javascript/
Best regards,
VinayApril 29, 2016 at 11:10 am #624241Hi, Vinnie,
yes, i can register the sript and i find the script in the source-code. But the script doesnt work. When i use the same script in the codeblock (inline) than the script works… Do you understand this?
April 29, 2016 at 11:17 am #624252Hey!
In your script make sure the “$” sign is replaced with jQuery. if you still have any issue please paste the script to pastebin.com and share the link with us and elabirate what it is suppose to do so we can try to make it work with wordpress.
Best regards,
VinayApril 29, 2016 at 11:30 am #624263thanks for the fast answer:
here is my script:http://pastebin.com/suTibJbU
It works inline, but not when i load it in an external file. I dont know why?
May 2, 2016 at 11:24 am #625644Hi,
Can you please create a temporary admin login and post it here privately?
Best regards,
YigitMay 2, 2016 at 12:42 pm #625707Hi,
yes… see the login-details in the private section.
on the site: http://www.hochzeitshaus-leipzig.com/ringe-und-schmuck i do not load the script inline with the codeblock, All other sites load the script inline with the codeblock.
I hope you can help me…
best regards
May 2, 2016 at 1:06 pm #625714Hey!
I added following code to functions.php file of your child theme and removed HTML code from your page
function custom_link_target(){ ?> <script type="text/javascript"> jQuery(document).ready(function() { var stickWidth = jQuery(".sticky-sbar ul li a").width()+32; var stickyBar = jQuery(".sticky-sbar").width()-stickWidth; jQuery(".sticky-sbar").css('right' , -stickyBar); jQuery(".sticky-sbar ul li a#see-me").toggle( function(){ jQuery(".sticky-sbar").animate({"right": 0}); //jQuery("a#see-me").css({"font-size":"16px","width":"30px"}); jQuery("a#see-me").text('X'); jQuery("a#see-me").css({"width":"25px"}); }, function(){ jQuery(".sticky-sbar").animate({"right": -stickyBar}); jQuery("a#see-me").text('April-Aktion'); jQuery("a#see-me").css({"width":"91px"}); } ); }); </script> <div class="sticky-sbar" style="right: -280px;"> <ul> <li><a href="#" id="see-me">AKTION!</a><span><span style="font-size:18px">10% Rabatt</span></style><br/>Im April bieten wir 10% Rabatt auf alle Trauringe<br/><a href="#" rel="nofollow">Termin vereinbaren</a></span></li> </ul> </div> <?php } add_action('wp_footer', 'custom_link_target');
Please review your website now
Best regards,
Yigit- This reply was modified 8 years, 6 months ago by Yigit.
May 2, 2016 at 3:07 pm #625820thanks Yigit!
now the script is in the footer. But why isnt it possible to load the script in an external file?
best regards
May 2, 2016 at 3:10 pm #625825Hey!
Please edit your file and remove Script tags
jQuery(document).ready(function() { var stickWidth = jQuery(".sticky-sbar ul li a").width()+32; var stickyBar = jQuery(".sticky-sbar").width()-stickWidth; jQuery(".sticky-sbar").css('right' , -stickyBar); jQuery(".sticky-sbar ul li a#see-me").toggle( function(){ jQuery(".sticky-sbar").animate({"right": 0}); //jQuery("a#see-me").css({"font-size":"16px","width":"30px"}); jQuery("a#see-me").text('X'); jQuery("a#see-me").css({"width":"25px"}); }, function(){ jQuery(".sticky-sbar").animate({"right": -stickyBar}); jQuery("a#see-me").text('April-Aktion'); jQuery("a#see-me").css({"width":"91px"}); } ); });
Cheers!
YigitMay 2, 2016 at 3:35 pm #625848thanks Yigit,
i removed script tags… but the script doesnt work in the external file. I dont know why…
May 2, 2016 at 3:46 pm #625859May 2, 2016 at 4:01 pm #625875yeah…
May 2, 2016 at 4:08 pm #625881Hey!
You were loading the file from the parent theme and Script tags were not removed there. I removed the file from parent theme and adjusted your code to load the file from child theme. Please flush browser cache and refresh your page now
Best regards,
YigitMay 2, 2016 at 4:29 pm #625901Thanks Yigit for the very good support.
How did you adjusted the code to load from the child theme?best regards Chris
May 2, 2016 at 4:30 pm #625904May 2, 2016 at 4:38 pm #625909ok… that was my mistake… Thankyou very much!!
May 2, 2016 at 5:20 pm #625942 -
AuthorPosts
- The topic ‘register my own javascript?’ is closed to new replies.