• Resolved EarlSnappy

    (@earlsnappy)


    Hi I’m using twenty eleven and am trying to add a small function script to my child functions.php I get the error:

    Parse error: syntax error, unexpected ‘(‘, expecting T_VARIABLE or ‘$’ in /home/familyte/public_html/addons/surfacedealscouk/wp-content/themes/myTheme/functions.php on line 10 (both the fucntion codes show as errors in dreamweaver

    The code I’m using is:
    <?php
    /**
    *Scroller
    */

    $(function() {
    $(“.scrollable”).scrollable();
    });
    ?>

    I got the code from a jquery site for making a simple image scroller – https://jquerytools.org/demos/scrollable/index.html

    Apologies if this is a bit of a newbie question. Any help much appreciated (I’ve removed the code from the site for the moment to do other work on the site). Earl

Viewing 2 replies - 1 through 2 (of 2 total)
  • Your problem is that you are trying to add JavaScript code into a PHP file. That won’t work.

    The biggest difference (apart from the languages being pretty different) is that PHP is a server-side language (executed on the server before being sent to the user) and JavaScript is client-side (executed in the users browser).

    What you need to do is save the Javascript in a new file and use the WP functions in your functions.php file to add the Javascript file to your theme. Look at wp_enqueue_script() for more info.

    Thread Starter EarlSnappy

    (@earlsnappy)

    Hi, thanks very much for that, I’ve had a look at your link and wish I had the time to fix what I want to do, but, I’m taking the shortcut and buying a plugin…not enough hours in the day, thanks Michael, Earl

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding Simple Code To functions.php’ is closed to new replies.