Menu bar

Saturday 28 June 2014

Redirection in wordpress with authorization and without authorization?

wp_redirect


The wp_redirect function is for redirecting all users to any absolute. URI. Absolute URIs are basically full URLs and look like this:

http://momin.com/book/http://momin.com/wp-contentredirecting-users.jpgftp://wordpress.com/transfer/

To redirect users with wp_redirect, place the following PHP snippet in your theme file with appropriate URL:

<?php
wp_redirect('http://example.com/'); exit; 
 ?>

The two parameters of wp_redirect are:
1> $location = The absolute URI to which the user will be redirected. No default.
2> $status = The status code to use. For example, 301, 302, etc. The default is 302.

<?php
// redirect to home page
wp_redirect(home_url()); exit; 
?>

<?php
// redirect back to current page
wp_redirect(get_permalink()); exit; 
?>

auth_redirect:

This extremely useful function checks whether or not the current user is logged in, and redirects them to the Login Page if not. By default, the user will be redirected back to the page from whence they came . Currently this function accepts no parameters.

<?php
 auth_redirect();
?>



No comments: