Viewing 19 posts - 1 through 19 (of 19 total)
  • Author
    Posts
  • #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

    #624219

    ok,

    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.
    #624224

    Hi!

    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,
    Vinay

    #624241

    Hi, 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?

    #624252

    Hey!

    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,
    Vinay

    #624263

    thanks 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?

    #625644

    Hi,

    Can you please create a temporary admin login and post it here privately?

    Best regards,
    Yigit

    #625707

    Hi,

    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

    #625714

    Hey!

    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.
    #625820

    thanks Yigit!

    now the script is in the footer. But why isnt it possible to load the script in an external file?

    best regards

    #625825

    Hey!

    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!
    Yigit

    #625848

    thanks Yigit,

    i removed script tags… but the script doesnt work in the external file. I dont know why…

    #625859

    Hey!

    Can you please post FTP credentials here privately as well?

    Best regards,
    Yigit

    #625875

    yeah…

    #625881

    Hey!

    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,
    Yigit

    #625901

    Thanks Yigit for the very good support.
    How did you adjusted the code to load from the child theme?

    best regards Chris

    #625904

    Hi!

    I changed “get_template_uri” to “get_stylesheet_uri”

    Regards,
    Yigit

    #625909

    ok… that was my mistake… Thankyou very much!!

    #625942

    Hi!

    You are welcome! Let us know if you have any other questions or issues

    Regards,
    Yigit

Viewing 19 posts - 1 through 19 (of 19 total)
  • The topic ‘register my own javascript?’ is closed to new replies.