647 posts
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
+5 more
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?

2468 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has referred 100+ members
  • Has been a beta tester for an Envato feature
+3 more
digitalimpact says

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

639 posts
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 2 years
+1 more
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.

647 posts
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
+5 more
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');

    }

}
647 posts
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
+5 more
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.

2468 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has referred 100+ members
  • Has been a beta tester for an Envato feature
+3 more
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.

647 posts
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
+5 more
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 :)

3424 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says

sounds like it should be called on template_redirect…

1502 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+2 more
OriginalEXE says

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

647 posts
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
+5 more
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 :)

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by