How to identifty post from its URL in 404 page?
How to identifty post from its URL in 404 page?
How to identifty post from its URL in 404 page?
This can be achieved with a simple custom plugin with 2 actions and 2 filters. First use the post_row_actions filter to alter the edit link on the admin page to attach a custom query called final_destination with the URI of the page we are currently on. Next we can use the edit_form_advanced action to add … Read more
A brief background on the behavior of 3xx status codes A 302 redirect is treated differently across browsers. Partially because of the variance of 302 in HTTP/1.0 and HTTP/1.1. HTTP 1.1 302 Found specifies that the request must not automatically be reprocessed at the returned location URI unless it can be confirmed by the user. … Read more
If I understood correctly, you need to check if the user is logged in, if not, redirect it to login page. If the user logs in succesfully, he should be redirected to the page he was trying to see. You can do this by using the redirect argument of wp_login_url(). This code should work (not … Read more
none of those conditionals will work at after_theme_setup. Look at the Action Reference page in Codex for the order actions are executed in a request. Try hooking template_redirect instead.
I don’t think this needs any WordPress at all. I would set up a single .php script setting the headers as such: header(“HTTP/1.1 301 Moved Permanently”); header(‘Refresh: 5; URL=http://jill.com/name_of_the_article’); And then whatever content you wish. Then I would set up a redirect to the said .php script. You would have to fetch the particular name … Read more
Figured it out, though this is the lamest solution ever: I hooked into wp_footer instead of template_redirect. If anyone has a better solution or place to hook in I’d love to hear about it – thanks! EDIT: That wasn’t the fix I thought it was. Turned out I was writing the function poorly, and did … Read more
The answer below doesn’t directly answer your question but provides a possible alternative solution. Drop has_shortcode( $post->post_content, ‘my-shortcode’ ) statement. There is no need to check this if you are validating nonce. So the validation should look something like this. function project_registration_login_redirection(){ if ( !isset( $_POST[‘my_submit’] ) ) { return; } // form validation here … Read more
get_page_by_path does something similar: function pagefromcat_template_redirect() { if ( ! is_category() ) { return; } $category = get_queried_object(); $page = get_page_by_path( $category->slug ); if ( $page instanceof WP_Post ) { $url = get_permalink( $page ); wp_safe_redirect( $url, 301 ); } } add_action( ‘template_redirect’, ‘pagefromcat_template_redirect’ );
Tom J Nowell confirmed what was happening. Inserting wp_redirect in a template causes the page either to partially load or not load at all. It needed to be placed before the opening <html> to work as it would load everything before </head> then stop.