[Support request] adding a script before the tag.

Home Forums Support [Support request] adding a script before the tag.

Home Forums Support adding a script before the tag.

  • This topic has 12 replies, 3 voices, and was last updated 6 years ago by Tom.
Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #531708
    Darcie

    I’m setting up a radio station site and we’d like to use a player that gives me the following code to insert in the php before the </body> tag.

    <!– place this code right before the </body> tag at the end of your page’s HTML code –>
    <script type=”application/javascript”>if(window===top){var CE_Player=new Object({stationCallSign:’BREEZE’,position:’top’,autostart:false,playerlocation:’streamdb8web’,fullPlayer:’v8′});document.write(‘<script src=”http://streamdb8web.securenetsystems.net/ce/js/playerwidget.min.js?’+Math.random()+'”>&lt;\/script>’);}</script>

    I’ve successfully inserted it in the footer php, but nothing happens. I confess, I’m new to the whole script thing, so is there something I’m missing?

    #531889
    Leo
    Staff
    Customer Support

    Hi there,

    I would recommend using wp_footer instead of editing footer.php so it’s saved through updates:
    https://docs.generatepress.com/article/hooks-overview/
    https://docs.generatepress.com/article/wp_footer/

    #532417
    Darcie

    Ok. I’m not sure I’m doing this right, because it’s still not working.

    I went to the GP Hooks section, chose wp_footer from the pull-down, and then inserted

    add_action( ‘wp_footer’, ‘radio_player’);
    function radio_player() { ?>
    <script type=”application/javascript”>if(window===top){var CE_Player=new Object({stationCallSign:’BREEZE’,position:’top’,autostart:false,playerlocation:’streamdb8web’,fullPlayer:’v8′});document.write(‘<script src=”http://streamdb8web.securenetsystems.net/ce/js/playerwidget.min.js?’+Math.random()+'”>&lt;\/script>’);}</script>
    <?php }

    I then selected “execute php” and hit “save hook.” Refreshed site, and nothing. What else do I do?

    (I told you I was a complete novice…)

    #532690
    Leo
    Staff
    Customer Support

    Hmm try just this:
    <script type=”application/javascript”>if(window===top){var CE_Player=new Object({stationCallSign:’BREEZE’,position:’top’,autostart:false,playerlocation:’streamdb8web’,fullPlayer:’v8′});document.write(‘<script src=”http://streamdb8web.securenetsystems.net/ce/js/playerwidget.min.js?’+Math.random()+'”><\/script>’);}</script>

    #532709
    Darcie

    Thanks, but I inserted that into the hook and nothing happened still.

    #532937
    Leo
    Staff
    Customer Support

    Then it’s probably best to check with the source of the code/plugin developer to see if there are anything else you need to do.

    #534812
    Darcie

    There has to be some sort of conflict with the theme’s code, since I have also tried embedding iframe code for a different radio player into the header, and that won’t work either. No help from the streaming developers.

    #535244
    Leo
    Staff
    Customer Support

    <iframe> should go directly into the content.

    Are you sure there aren’t anything else you need to do after inserting the code into wp_footer?

    There shouldn’t be any conflicts on this part as GP simply adds the code you inserted.

    Maybe try it with a twenty series themes?

    #535918
    Darcie

    This is my problem. I did enter the code directly into the content. It didn’t do anything.

    Also, I don’t see the script on the page code after I use the hook. I really think I’m not understanding how to use the hook.

    #536291
    Leo
    Staff
    Customer Support

    Hook just takes the code you added and doesn’t interfere with it or anything.

    If it asked to place before the end of body then wp_footer is definitely the right spot.

    Where did you get the code? If the developer isn’t answering perhaps it’s no longer supported?

    Can you try it with a twenty series theme and see if it works correctly?

    #538418
    Darcie

    Just got the following response from the script developer:

    Does your website have CORS enabled? I ask because of the following message that shows in the debugger, when I visit:

    Blocked loading mixed active content “http://streamdb8web.securenetsystems.net/ce/js/playerwidget.min.js?0.43080983946222295”

    What is CORS? Is it something I have control over?

    #538694
    Darcie

    Added the revised script directly into the footer.php and it works fine. Clearly I’m not understanding the concept of hooks.

    #538820
    Tom
    Lead Developer
    Lead Developer

    Perhaps your server is messing up the code while it’s being saved.

    Instead, use this code:

    add_action( 'wp_footer', 'tu_add_radio_script' );
    function tu_add_radio_script() {
        ?>
        <script type=”application/javascript”>if(window===top){var CE_Player=new Object({stationCallSign:’BREEZE’,position:’top’,autostart:false,playerlocation:’streamdb8web’,fullPlayer:’v8′});document.write(‘<script src=”http://streamdb8web.securenetsystems.net/ce/js/playerwidget.min.js?’+Math.random()+'”><\/script>’);}</script>
        <?php
    }

    Add it using one of these methods, instead of GP Hooks: https://docs.generatepress.com/article/adding-php/

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.