• I am a newbie to WP so forgive my ignorance. I want to run an external javascript

    <script src=”swfobject.js” language=”javascript” type=”text/javascript”></script>

    which makes this script in my index page work

    <script type=”text/javascript”>
    // <![CDATA[
    var so2 = new SWFObject(“swfs/home.swf”, “home”, “1120”, “765”, “9”, “#000000”);
    so2.addParam(“menu”, “false”);
    so2.addParam(“scale”, “noscale”);
    so2.addParam(“wmode”, “transparent”);
    so2.write(“home_div”);
    // ]]>
    </script>

    I have tried some suggestions in wp help but cannot get it to work. It does work on another non-wp site,.Any suggestions??

Viewing 3 replies - 1 through 3 (of 3 total)
  • You need to enque the script (and its dependancies), this gets it included in the page header in the correct order, details are here:
    https://codex.www.ads-software.com/Function_Reference/wp_enqueue_script

    Presumably on your index page, you are putting the <script> code into the page template, or a suitable widget type etc.

    Thread Starter nm5z

    (@nm5z)

    I tried the snippet below but it doesn’t work so think it is right. Tried it in page.php but not real sure where to put it.

    <?php \
    function wpb_adding_scripts()
    {wp_register_script(‘swfobject_script’, plugins_url(‘swfobject.js’, __FILE__), array(‘jquery’),’1.1′, true);
    wp_enqueue_script(‘swfobject_script’); }
    add_action( ‘wp_enqueue_scripts’, ‘wpb_adding_scripts’ );
    ?>

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    First instead of this:

    <?php \

    Write this:

    <?php

    Then put that code in your Child Theme functions.php file.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Run external javascript’ is closed to new replies.