0

In WordPress the default permalink URL like this

http://***.com/?p=123

when I change it to this:

http://***.com/new/sample-post/

Is that possible I still can get the default permalink link text, because the second URL is too long, it looks not so good when someone share it.

2 Answers 2

2

When you are editing a post you can notice the URL in your browser looks like

http://***.com/wp-admin/post.php?post=1351&action=edit

The number in the URL corresponds to the ID of your post. So you can access your post with that ID. In this example the short link for the post would be

http://***.com/?p=1351

When a visitor browsers this URL she will be redirected to the full URL if you have the correct options set in Settings > Permalinks.

If you need to get the short URL programatically you can use the wp_get_shortlink() function. This function returns the link, which can then be printed.

2
  • Thanks, Actually, I want display this link at end of each post then the browser can copy this shorter link to share.
    – user18787
    Commented Nov 17, 2016 at 1:51
  • 1
    @user18787 I updated my answer. Commented Nov 17, 2016 at 2:06
1

You can concatenate a url with the ID using get_site_url. This assumes the ID is valid.

<?php 

   echo get_site_url(null, '/?p=' . get_the_ID() );

?>

Although wp_get_shortlink() above seems like a better choice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.