Redirecting the user to the published page using wp_redirect
Today I will talk about a small piece of code, which can help bloggers in speeding up the publication of their articles in the WordPress engine.
Today we'll talk about, how to redirect the blogger to the published page after updating or publishing a new post. The following code needs to be added to the function.php file.
At the code fragment:
1 2 3 4 5 6 7 8 9 10 11 |
add_filter('redirect_post_location', 'redirect_to_post_on_publish_or_save'); 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); } } } } |
/*
- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.