Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home Tips And Tricks Get WordPress Short Link And Full Link To A Post

Get WordPress Short Link And Full Link To A Post

There are 2 ways to get the Short Link or Full Link (permalink) to a post by using wp_get_shortlink() or get_permalink() function respectively.

Some case you want to get the link of the current page/post or a particular page/post with specified ID for sharing the link to Social Media site such as Facebook, Twitter, Digg and other bookmarking services you can use either of following ways:

1. Get the Full Link – permalink

get_permalink() function has a input parameter named ID as optional gets the full link of a page/post. It will return the link of the current page/post if we use the function without the ID.

Example:

1. Link to current page/post:

<?php
	echo "Full link for this post: <br>";
	echo get_permalink();
	// return: http://4rapiddev.com/tips-and-tricks/get-wordpress-short-link-and-full-link-to-a-post/
?>

<?php echo "Full link for this post: <br>"; echo get_permalink(); // return: http://4rapiddev.com/tips-and-tricks/get-wordpress-short-link-and-full-link-to-a-post/ ?>

2. Link to page ID 9 and post ID 512:

<?php
	echo "Full link for post ID 512: <br>";
	echo get_permalink(512) . "<br>";
	// return: http://4rapiddev.com/internet/lg-optimus-2x-key-specifications/
 
	echo "Full link for page ID 9: <br>";
	echo get_permalink(9) . "<br>";
	// return: http://4rapiddev.com/about/
?>

<?php echo "Full link for post ID 512: <br>"; echo get_permalink(512) . "<br>"; // return: http://4rapiddev.com/internet/lg-optimus-2x-key-specifications/ echo "Full link for page ID 9: <br>"; echo get_permalink(9) . "<br>"; // return: http://4rapiddev.com/about/ ?>

2. Get Short Link

wp_get_shortlink() function is specially useful when you want to share the link on Twitter or other service which limit characters.

<?php
	echo wp_get_shortlink();
	// return: http://4rapiddev.com/?p=525
?>

<?php echo wp_get_shortlink(); // return: http://4rapiddev.com/?p=525 ?>

Mar 31, 2011Hoan Huynh
View Email HTML Source In Microsoft Outlook 2007Share Page On Facebook With Thumbnail Featured Image
You Might Also Like:
  • Share Link/ Url Of Facebook, Twitter, Google Plus, Stumbleupon, Reddit, Digg and Tumblr
  • Keep Posting When You’re On Vacation With WordPress Post TimeStamp
  • WordPress Check If Post Is In Category
  • Facebook Publish To Wall With External Link And Track Callback
  • PHP Auto Post A Story Content To Digg, StumbleUpon, Tumblr and LinkedIn
  • Add And Get Custom Field In WordPress
  • How To Track Website With Multiple Google Analytisc Accounts
  • WordPress Delete Unused Post Tags By SQL Command
  • PHP auto post tweet to Twitter
  • Place Facebook Like Button On WordPress
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

11 years ago Tips And Tricksget_permalink, permalink, Wordpress, wp_get_shortlink218
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
24,451 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
21,829 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
17,646 views
JQuery Allow only numeric characters or only alphabet characters in textbox
14,984 views
C# Read Json From URL And Parse/Deserialize Json
11,710 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Things to Learn about Installingderm Loan Type S
  • Online Photo Editor – Free Photoediting Software
  • A Guide to Finding the Best Paper Sellers
  • Photoediting in Home Isn’t Hard to Do!

  • Free Photo Editor Online
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (27)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (647)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development