Scenario: The urls and titles of the posts on my blog are usually very long. Whenever I or anyone else tweets the post, I don’t find any space to add the hashtags or quoted retweet text. I don’t want to shorten the titles of the posts, so the other option is to shorten the url. For this purpose I want to grab the shortlink from wordpress post in this format
http://mydomain.com/?p=(post ID)
Can you please tell me how to do it?
Use wp get shortlink
Returns URL based on numerical ID, i.e. http://example.com/?p=1234
https://codex.wordpress.org/Function_Reference/wp_get_shortlink
Usage
<?php $short_link = wp_get_shortlink(); ?>
or
<?php echo wp_get_shortlink(); ?>
Source File
wp_get_shortlink() is located in wp-includes/link-template.php.
You can go to Settings -> Permalinks and set it to ‘default’ (or ‘numeric’ if you prefer) and then call
in your âtweet thisâ link.
or you can use this: Twitter Friendly Links WordPress Plugin