Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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