Where does wp_redirect need to be placed to make it work?

I’ve got a front end post editing page located at mysite/post_id/edit and am trying to redirect users that are not the author back to the post. Here’s the code I’m working with: <?php global $current_user; get_currentuserinfo(); if($post->post_author != $current_user->ID): wp_redirect( the_permalink() ); exit; ?> The problem I’ve been having is that this seems to just … Read more

wp_redirect not working after submitting form

I’m using this redirect after inserting a post. It’s not working, it only refreshes the page the form is on. I know the $pid is getting the post ID so what is the problem? This is the very end of my php code for handling the form submission. $pid = wp_insert_post($new_post); update_post_meta($pid,’domain’,$domain); update_post_meta($pid,’keywords’,$keywords); wp_redirect( get_permalink($pid) … Read more

Redirect page URL to home URL without using a plugin

How do I redirect this page URL, http://localhost/wordpress_rnd/?page_id=2, to the home URL, http://localhost/wordpress_rnd/, without using any plugins? 4 s 4 The correct way to do this is using the template_redirect hook by adding a function to your functions.php: function redirect_to_home() { if(!is_admin() && is_page(‘2’)) { wp_redirect(home_url()); exit(); } } add_action(‘template_redirect’, ‘redirect_to_home’);

Pretty permalinks for search results with extra query var

I’d like to know how I can rewrite a search URL that also contains an extra query var into a pretty permalink using wp_redirect and the template_redirect hook. I have taken the code from the Nice Search plugin which works fine to change http://example.com?s=africa into http://example.com/search/africa: add_action( ‘template_redirect’, ‘my_rewrite’ ) ); function my_rewrite() { if … Read more

wp_redirect() function is not working

wp_redirect($post->guid) is not working. How can I fix this? This is my code: if(isset($_REQUEST[‘vid’]) ){ $id=$_REQUEST[‘vid’]; $post_title=”sasa”; $post_content=”zxczxczxc”; $new_post = array( ‘ID’ => ”, ‘post_author’ => $user->ID, ‘post_content’ => $post_content, ‘post_title’ => $post_title, ‘post_status’ => ‘publish’, // NOW IT’S ALREADY AN ARRAY ); $post_id = wp_insert_post($new_post); // This will redirect you to the newly created … Read more

wp_redirect() – headers already sent

I am trying to use wp_redirect() to redirect the user after successfully submitting a signup form on the page. It’s not working and shows the following error: Warning: Cannot modify header information – headers already sent by (output started at /Applications/MAMP/htdocs/theme/wp-content/themes/test/header.php:10) in /Applications/MAMP/htdocs/theme/wp-includes/pluggable.php on line 1178 I understand there has been already output before, that’s … Read more

Admin Page Redirect

Is it possible to redirect users to an admin page if they access another admin page? For example if they a user ever hits “all pages” /wp-admin/edit.php?post_type=page they would get redirected to “add New page” /wp-admin/post-new.php?post_type=page 3 /** * Redirect admin pages. * * Redirect specific admin page to another specific admin page. * * … Read more