631 posts
  • United Kingdom
  • Sold between 10 000 and 50 000 dollars
  • Most Wanted Bounty Winner
  • Interviewed on the Envato Notes blog
  • Referred between 50 and 99 users
  • Bought between 50 and 99 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 2-3 years
UBLThemes says

Hi, i am just updating my wordpress and i am wanting to write a redirect function, i have tried to use the header(); but this does not work.

Is javascript the only way?

2440 posts
  • Has been a member for 5-6 years
  • Exclusive Author
  • Europe
  • Bought between 10 and 49 items
  • Referred between 100 and 199 users
  • Sold between 100 and 1 000 dollars
  • Envato Studio (Microlancer) Beta Tester
digitalimpact says

WordPress already has a redirect function:
http://codex.wordpress.org/Function_Reference/wp_redirect

639 posts
  • Exclusive Author
  • Sold between 100 and 1 000 dollars
  • Bought between 10 and 49 items
  • Has been a member for 2-3 years
  • Haiti
Crakken says
Can be done with HTML :
Create an index.html file in the directory where you want to redirect people and paste in this:

    <head> 
        <meta http-equiv="refresh" content="0; url=http://crakken.com"> 
    </head> 

        Redirecting...

Or simply paste the meta in the head tag of your file.

631 posts
  • United Kingdom
  • Sold between 10 000 and 50 000 dollars
  • Most Wanted Bounty Winner
  • Interviewed on the Envato Notes blog
  • Referred between 50 and 99 users
  • Bought between 50 and 99 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 2-3 years
UBLThemes says

WordPress already has a redirect function:
http://codex.wordpress.org/Function_Reference/wp_redirect

Even that is not working.

I have created it like normal:

add_action('wp_head', 'ubl_check_page');
function ubl_check_page(){

    global $wpdb;

    $pagechanger= $wpdb->get_row("SELECT pagechange FROM ifpagechange WHERE id=1", "OBJECT");

    if($pagechanger->pagechange == 1){

        $ubllocation = UBL_PATH . 'page.php';
        wp_redirect( $ubllocation, '302');

    }

}
631 posts
  • United Kingdom
  • Sold between 10 000 and 50 000 dollars
  • Most Wanted Bounty Winner
  • Interviewed on the Envato Notes blog
  • Referred between 50 and 99 users
  • Bought between 50 and 99 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 2-3 years
UBLThemes says

Can be done with HTML :
Create an index.html file in the directory where you want to redirect people and paste in this:

    <head> 
        <meta http-equiv="refresh" content="0; url=http://crakken.com"> 
    </head> 

        Redirecting...

Or simply paste the meta in the head tag of your file.

It wont do this as its not putting it actually within the head tag so the meta will not work as needed.

2440 posts
  • Has been a member for 5-6 years
  • Exclusive Author
  • Europe
  • Bought between 10 and 49 items
  • Referred between 100 and 199 users
  • Sold between 100 and 1 000 dollars
  • Envato Studio (Microlancer) Beta Tester
digitalimpact says


WordPress already has a redirect function:
http://codex.wordpress.org/Function_Reference/wp_redirect

Even that is not working.

I have created it like normal:

add_action('wp_head', 'ubl_check_page'); function ubl_check_page(){ global $wpdb; $pagechanger= $wpdb->get_row("SELECT pagechange FROM ifpagechange WHERE id=1", "OBJECT"); if($pagechanger->pagechange == 1){ $ubllocation = UBL_PATH . 'page.php'; wp_redirect( $ubllocation, '302'); } }

You need to add it earlier, it’s clearly stated in the docs:

Please note: wp_redirect will not be called if the page has started, so make sure to call it higher up.

Try adding it to pre_get_posts or, worst case, init.

631 posts
  • United Kingdom
  • Sold between 10 000 and 50 000 dollars
  • Most Wanted Bounty Winner
  • Interviewed on the Envato Notes blog
  • Referred between 50 and 99 users
  • Bought between 50 and 99 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 2-3 years
UBLThemes says



WordPress already has a redirect function:
http://codex.wordpress.org/Function_Reference/wp_redirect

Even that is not working.

I have created it like normal:

add_action('wp_head', 'ubl_check_page'); function ubl_check_page(){ global $wpdb; $pagechanger= $wpdb->get_row("SELECT pagechange FROM ifpagechange WHERE id=1", "OBJECT"); if($pagechanger->pagechange == 1){ $ubllocation = UBL_PATH . 'page.php'; wp_redirect( $ubllocation, '302'); } }

You need to add it earlier, it’s clearly stated in the docs:

Please note: wp_redirect will not be called if the page has started, so make sure to call it higher up.
Try adding it to pre_get_posts or, worst case, init.

Spot On :) thanks :)

Didnt think that it needed to be inserted before hand, thanks :)

3192 posts
  • Sold between 5 000 and 10 000 dollars
  • United States
  • Bought between 10 and 49 items
  • Has been a member for 4-5 years
  • Exclusive Author
organicbee says

sounds like it should be called on template_redirect…

1466 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
  • Croatia
OriginalEXE says

Also, $status should be integer, not string, so you should remove ’’

631 posts
  • United Kingdom
  • Sold between 10 000 and 50 000 dollars
  • Most Wanted Bounty Winner
  • Interviewed on the Envato Notes blog
  • Referred between 50 and 99 users
  • Bought between 50 and 99 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 2-3 years
UBLThemes says

Also, $status should be integer, not string, so you should remove ’’

Yeah i know, it was just a quick post, it is not my exact coding as didnt want to show url etc. The single quotes was just a quick typo on here :)

by
by
by
by
by
by