This quick tutorial explains how to display a hyperlink to the submitted post using USP Pro version 1.7 or better.
2-step tutorial
Normally after a user submits a post, they may be redirected to the submitted post, remain on the same page, or get redirected to some other specified URL. All of this is in the settings, fine and well. But let’s say that, instead of redirecting the user, you want to keep them on the submission page, but display a link to their newly submitted post. Something like:
<a href="http://example.com/?p=123">Visit your new post!</a>
Here is how to do it in two steps:
Step 1
Make sure that new posts are set to “Always publish immediately”. Visit USP Pro ▸ General ▸ Basic Settings ▸ “Auto Publish Posts”.
Step 2
Add the following code to a JavaScript file that is included on the web page (e.g., usp-pro.js
):
function getQueryParameters(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
jQuery(document).ready(function($) {
var post_id = getQueryParameters('post_id');
var current = window.location.host + '/' + window.location.pathname;
if (post_id != 'undefined' && post_id != null && post_id != '') {
$('.usp-success').append(' <a href="http://' + current + '?p=' + post_id + '">Visit your post!</a>');
}
});
That’s all there is to it. When properly included, this code will display a link to the newly submitted/published post. Feel free to customize the markup et al as needed to suit your needs.