1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Wordpress, why is my script not working?

Discussion in 'Blogging' started by Snatch2014, Feb 8, 2015.

  1. Snatch2014

    Snatch2014 Regular Member

    Joined:
    Dec 11, 2014
    Messages:
    288
    Likes Received:
    44
    Hi!

    I know PHP, HTML, CSS and JavaScript but I'm kind of new when it comes to wordpress and digging in the source code.

    How ever I have made a very simple JavaScript Script. There is 1 .js file with alot of code, and in the <head> tag there is only 2 lines. The script works fine when I test it on a plain html page. But when I try it with wordpress it does'nt work.

    I guess it has something to do with the path to the external .js file (src="js/file.js").



    What am I missing? Why is'nt my script loading correctly?
     
  2. happiweb

    happiweb Newbie

    Joined:
    Feb 10, 2015
    Messages:
    1
    Likes Received:
    0
    Occupation:
    wordpress, web, seo
    Location:
    Viet Nam
    Home Page:
    You try code bellow:
    <script type="text/javascript" src="<?php bloginfo('template_url') ?>/js/file.js"></script>

    <?php bloginfo('template_url') ?>: path real to folder your theme
     
  3. iAuthority

    iAuthority Jr. VIP Jr. VIP

    Joined:
    Jan 20, 2013
    Messages:
    2,202
    Likes Received:
    284
    Gender:
    Male
    Occupation:
    SEO,Link Building,Blogging.
    Home Page:
    // Register Script
    function custom_scripts() {

    }

    // Hook into the 'wp_enqueue_scripts' action
    add_action
    ( 'wp_enqueue_scripts', 'custom_scripts' );

    you can try the script , it works properly