Make WordPress Core

Opened 7 years ago

Last modified 7 years ago

#41204 new enhancement

Placement of wp_redirect() in template

Reported by: milana_cap's profile milana_cap Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Themes Keywords:
Focuses: docs, template 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 (7)

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


7 years ago

#2 @SergeyBiryukov
7 years ago

  • Component changed from General to Themes
  • Focuses template added

#3 follow-up: @xkon
7 years ago

Duplicate of https://meta.trac.wordpress.org/ticket/2751 .

Best regards,
Konstantinos

#4 in reply to: ↑ 3 @milana_cap
7 years ago

Replying to xkon:

Duplicate of https://meta.trac.wordpress.org/ticket/2751 .

Best regards,
Konstantinos

That other ticket is invalid. I posted it to a wrong place.

#5 follow-up: @xkon
7 years ago

@milana_cap ,

Sorry I didn't want to show disrespect or anything.

I said it was a duplicate because as it was stated from cofee2code on your other post, you should contribute your Note in https://developer.wordpress.org/reference/functions/wp_redirect/ , in the user notes.

This section of the website would be used only if you wanted to add a note in the actual function code.

What you are suggesting has nothing to do with the inline code though. It's a template reference of how it could be used so it should be on the user notes on the developers documentations.

Best regards,
Konstantinos

#6 in reply to: ↑ 5 @milana_cap
7 years ago

Oh, no need to be sorry. You did not show any disrespect. I am sorry if you got that impression.

I've been going with this issue all over the place :D and am not sure where it belongs any more.. haha

All the best,
Milana

Replying to xkon:

@milana_cap ,

Sorry I didn't want to show disrespect or anything.

I said it was a duplicate because as it was stated from cofee2code on your other post, you should contribute your Note in https://developer.wordpress.org/reference/functions/wp_redirect/ , in the user notes.

This section of the website would be used only if you wanted to add a note in the actual function code.

What you are suggesting has nothing to do with the inline code though. It's a template reference of how it could be used so it should be on the user notes on the developers documentations.

Best regards,
Konstantinos

#7 @xkon
7 years ago

You can use this link here -> https://developer.wordpress.org/reference/functions/wp_redirect/#add-note-or-feedback , and just type your explanation of the function there so it will be added in the User Notes section of that page that is about the wp_redirect. So when users are trying to find information they can see your note / suggestion as well in the user manual.

Best regards,
Konstantinos

Note: See TracTickets for help on using tickets.