WordPress.org

Making WordPress.org

Opened 9 months ago

Closed 9 months ago

Last modified 6 months ago

#2751 closed enhancement (invalid)

Placement of wp_redirect()

Reported by: milana_cap Owned by:
Milestone: Priority: normal
Component: Developer Hub Keywords:
Cc:

Description

It doesn't say on | this page where in template file should wp_redirect() function be called. If placed in wrong place, there could be created confusion and impression that function doesn't work.

So, it should be placed before get_header();

In case page is redirected only under certain condition, it would be something like:

/**
 * Redirect only if this condition is met
 */
if ( certain_condition ) {
	wp_redirect( $location );
	exit;
}
/**
 * Otherwise render the page
 */
get_header();

Change History (3)

#1 @coffee2code
9 months ago

  • Resolution set to invalid
  • Status changed from new to closed

Hi @milana_cap, thanks for the suggestion! There are two places where such a request can be better handled:

  1. You can contribute a note to the reference page itself: https://developer.wordpress.org/reference/functions/wp_redirect/. You'll see there are already two User Contributed Notes for the function at the moment (though unrelated to your suggestion). That way any one else visiting the page can see your tip.
  1. If you feel this information deserves to be part of the function's inline documentation itself, you can open a ticket for it on https://core.trac.wordpress.org/ and choose the "docs" focus. Inline docs are automatically added to the Code Reference when parsed after each WordPress release.

#2 @milana_cap
9 months ago

Hi @coffee2code,
sorry for missing the right place. Will post it as suggested. Thank you.

This ticket was mentioned in Slack in #forums by sergey. View the logs.


6 months ago

Note: See TracTickets for help on using tickets.