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

Once you’re in the template it’s too late, as headers have already been sent. You have to hook earlier in the request to check, like the template redirect hook: add_action( ‘template_redirect’, ‘wpse52455_redirect’ ); function wpse52455_redirect(){ // do your check and call wp_redirect here } Note that this will get called on every request, so you … Read more

How to use nonce with front end submission form?

Use the following code inside just before tag on your front end code. wp_nonce_field(‘name_of_your_action’, ‘name_of_your_nonce_field’); The above code will generate two hidden inputs inside your form tag. Now you can verify your nonce in the backend where you will process your form. Use the following code to verify the nonce you just created above. if(wp_verify_nonce($_REQUEST[‘name_of_your_nonce_field’], … Read more

Pretty permalinks for search results with extra query var

To modify the search rewrite rules you can hook into the search_rewrite_rules filter. You can either add the extra rewrite rules that match post types yourself, or you can change the default “search rewrite structure” to also include the post type and then re-generate the rules (there are four rules: one standard, one with paging … Read more

wp_redirect() function is not working

Two things wrong here: Don’t use $post->guid as an url You must exit() after using wp_redirect() (see the Codex) wp_redirect() does not exit automatically and should almost always be followed by exit. To redirect to your new post’s page: //….. code as in question $post_id = wp_insert_post($new_post); $url = get_permalink( $post_id ); wp_redirect($url); exit();

wp_redirect() – headers already sent

Found the answer (via) Instead of using the function I added an action to “wp_loaded”, that makes sure that it gets loaded before any headers are sended. <?php add_action (‘wp_loaded’, ‘my_custom_redirect’); function my_custom_redirect() { if ( isset( $_POST[‘subscribe’] ) ) { $redirect=”http://example.com/redirect-example-url.html”; wp_redirect($redirect); exit; } } ?>

Admin Page Redirect

/** * Redirect admin pages. * * Redirect specific admin page to another specific admin page. * * @return void * @author Michael Ecklund * */ function disallowed_admin_pages() { global $pagenow; # Check current admin page. if ( $pagenow == ‘edit.php’ && isset( $_GET[‘post_type’] ) && $_GET[‘post_type’] == ‘page’ ) { wp_redirect( admin_url( ‘/post-new.php?post_type=page’ ) … Read more