There is a snippet of JavaScript code I would like to include in a WordPress page. What's happening is the code isn't loading properly and it's getting hung up somewhere in WordPress's native redirect commands.
This is the code I was supplied (and which works on their site and on other non-WordPress domains):
<link href="http://www.othersite.com/thepage.php?uid=1234" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="http://www.othersite.com/thepage.php?uid=1234"></script>
<a id="OtherSite" target="_blank" href="http://www.othersite.com" title="The Other Site">Link to OtherSite</a>
If I look directly at the my page source with the code, it is pointing in the right direction. If I open my browser's javascript console for the exact same page, it shows the link has redirected itself back to my domain so instead of going to othersite.com/page.php it is actually trying to get to mysite.com/page.php
.
I have tried
Redirect 301 mysite.com/thepage.php othersite.com/thepage.php
I have also tried adding the following to my functions.php
(which broke everything)
<?php
if (function_exists('myscript')) {
function myscript() {
if (is_page('ThePage')) {
wp_register_script('myscript', 'http://www.othersite.com/thepage.php?uid=1234'__FILE__);
wp_enqueue_script('myscript');
}
}
}
add_action('init', 'myscript');
?>
Does anyone know how I can get this to work?
EDIT @cole
Honestly I have no idea why the __ FILE__
is there. I know enough about this stuff to be a menace to myself but not really enough to create my own work. The PHP stuff is what I put together based on the tutorial The Ins and Outs of The Enqueue Script For WordPress Themes and Plugins.
EDIT @morganestes I thought that was a little odd myself, but that's what they gave me. The CSS isn't intended to mess with anything in the othersite php, just the link-back to them at the bottom. I put your code into functions.php and while it didn't exactly break the site like my other attempts, it did have the unfortunate effect of being placed at the very top outside any of my theme elements. It also didn't fix the problem; wordpress is still changing the link from othersite.com to mysite.com.
EDIT @helga The fundamental problem is that Wordpress is taking it upon itself to magically rewrite my outbound link to refer to a non-existent internal location.
thepage.php?uid=1234
)? Also, are you just trying to load a script from an external source, as the code suggests?(thepage.php?uid=1234)
and not a script? morganestes' answer will get your script loaded properly. After that, it seems like a scripting issue.wp_remote_get()
and the iFrame plugin. Maybe either will be helpful. (or not)