Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@saeidzebardast
Created December 21, 2015 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saeidzebardast/0c99510f5be811ce2929 to your computer and use it in GitHub Desktop.
Save saeidzebardast/0c99510f5be811ce2929 to your computer and use it in GitHub Desktop.
WordPress: Redirect to add new post on publish or save
<?php
add_filter('redirect_post_location', 'redirect_to_add_new_post_on_publish_or_save');
function redirect_to_add_new_post_on_publish_or_save(){
if (isset($_POST['save']) || isset($_POST['publish'])) {
$pl = get_admin_url('', 'post-new.php');
if ($pl) {
wp_redirect($pl);
}
}
}
function redirect_to_post_on_publish_or_save($location){
if (isset($_POST['save']) || isset($_POST['publish'])) {
if (preg_match("/post=([0-9]*)/", $location, $match)) {
$pl = get_permalink($match[1]);
if ($pl) {
wp_redirect($pl);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment