Archived topic
adding a script before the tag.
12 replies · Started by Darcie on March 26, 2018
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()+'"><\/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?
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/
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()+'"><\/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...)
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>
Thanks, but I inserted that into the hook and nothing happened still.
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.
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.
<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?
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.
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?
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?
Added the revised script directly into the footer.php and it works fine. Clearly I'm not understanding the concept of hooks.
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/