Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using an onclick function to redirect the user if they are not login.

I am calling a php function in achor tag like this

<a href="#" class="fright hrtacnhor" onclick="<?php checkstatus(); ?>">save to my favorite</a>

and the function I am using is

<?php
function checkstatus(){
    wp_redirect( get_permalink( 8 ) );exit; 
}
?>

But the problem is that when i click it not call the fucntion. I also try to use wp_redirect() function directly in onclick but it not working so any one please guide me how it works. Thanks

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

You could do the redirect by means of JavaScript:

<a href="#" class="fright hrtacnhor" onclick="window.location='<?php echo get_permalink( 8 ) ?>'">save to my favorite</a>

But why yould you want to do it that way and not just use the link directly?

share|improve this answer
    
Because when any user click on it. Div flip and store some data related to that post. So for this purpose user have to login first. –  Adi Mar 11 '13 at 8:13
add comment

You can't use PHP this way.

PHP is static and will is parsed when the output is generated. When the page is viewed PHP can't be called directly anymore. Please read the documentation of PHP about this.

In this case (I guess you simply want to get the visitor on the other page) you can put the get_permalink() directly in the href property:

<a href="<?php echo get_permalink( 8 ); ?>" class="fright hrtacnhor">save to my favorite</a>

Or, if you want to use JavaScript (by the answer of t f):

<a href="#" class="fright hrtacnhor" onclick="javascript:window.location='<?php echo get_permalink( 8 ); ?>';">save to my favorite</a>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.