0

I have a WordPress site which I am calling a URL from a custom field using the following

<?php $redirect_url = get_post_meta($post->ID, 're_url', true);

I am also using TinyBox2 to display this URL in a popup box, using the callback function I have set it to run a function in the footer that redirects to, for now, www.google.com

TinyBox
-------
<div class="redirect" onclick="TINY.box.show({html:'Your website is : <br /><?php echo get_post_meta($post->ID, 're_url', true); ?>',animate:true,close:true,mask:false,boxid:'success',openjs:function(){openJS()}})"></li>

Footer
------
<script type="text/javascript">
    function openJS(){setTimeout("top.location.href = '$redirect_url'",5000);}
</script<

This isnt working as I want it to, can anybody explain where I am going wrong?

2 Answers 2

1

You need to write php variable, so that javascript can pick it up!!

function openJS(){setTimeout("top.location.href = '<?php echo $redirect_url; ?>'",5000);}
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, can't believe I was missing the obvious :)
1

Set timeout accepts a function, not a string.

EDIT: Here's some (untested) code. This should get you going in the right direction, I hope.

function openJS(){
   window.setTimeout(function(){
      window.location = "<?php echo $URL ?>";
   }, 5000);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.