Would you like to export all of your published WordPress posts’ shortlink URLs to a big list quickly and easily? If so, then this post is for you as we show you how, in a few simple steps, you can get all the links you want.

WordPress Plugin

We have created a WordPress plugin that carries out this task for you, whenever you want! You can go ahead and download it from our site using the button below:

LinkGather WordPress Plugin

You can also install our plugin from the official WordPress Plugin Repository using the button below:

LinkGather WordPress Plugin

Step by Step Guide

The links are a module of the JetPack plugin installation. I’m sure most of you are familiar with JetPack but if you do not have this module activated, go into your JetPack settings and active it first.


You will also need to ensure that you either have FTP access or File Manager access to your WordPress installation. This is because we are going to upload a PHP file to the root of your WordPress installation folder. This is the file that we will then run to gather all the shortlinks and echo them out into a big list within your internet browser.

PHP Code

Once you are happy that you have upload access to the root of your WordPress installation, go ahead and create a simple text file. You can use the built in Windows Notepad, but I’d suggest that you use Notepad++ and it is much better for writing any sort of code. But please, do not try and use Microsoft Word or Google Docs as this will more than like screw up the PHP code formatting.

Once you have your text file, save it to a location of your choice (Desktop is fine) and you can name it anything you like, but for the purposes of this guide, we will use getlinks.php.

Now copy and paste the PHP code below into the text file:

include "wp-load.php";
$posts = new WP_Query('post_type=any&posts_per_page=-1&post_status=publish');
$posts = $posts->posts;
foreach($posts as $post) {
switch ($post->post_type) {
$shortlink = wp_get_shortlink($post->ID);
echo "\n{$shortlink}";

Please be aware of the syntax formatting though, sometimes it can get a bit screwed up copied from a web browser, just check the speech marks and semicolons etc.

Video Demo

See the video below for a quick example of the formatting to look out for and the full process:

Save the text file again so that the file has the PHP in it.

You should now ensure that the file extension is php and not txt which can be a common mistake to make.

Upload to Your WordPress Installation Root

Connect to your WordPress installation root and upload the getlinks.php file.

Do not put it in a subfolder or it will not work.

You are now ready to get all of your published posts shortlinks. Just go to your blog URL and then add the getlinks.php file to the end of your URL. So for my blog here, you would use:

This should then go off and gather all the shortlinks – this could be a few seconds or maybe longer depending on the size of your site. My blog here has over 1000 posts and it takes 2-3 seconds to complete.

Your web browser should then show you a big list of all your links: shortlinks output

Removing the Blank Lines

You may notice some gaps in the list, this is expected but you can copy and paste this list into something like Microsoft Excel and then just use the Remove Duplicates option under the Data ribbon:

Microsoft Excel Remove Duplicates

You will then get a pop up telling you how many lines it has removed and how many unique values remain:

Removed Duplicates

You will then have a big list of all your shortlinks!


If you have any problems with any steps of this guide, please feel free to leave us a message below in the comments section and we will try to get back to you as soon as we can.

Click to rate this post!
[Total: 0 Average: 0]

Discover more from TechyGeeksHome

Subscribe to get the latest posts to your email.

Avatar for Andrew Armstrong

Andrew Armstrong

Founder of TechyGeeksHome and Head Editor for over 15 years! IT expert in multiple areas for over 26 years. Sharing experience and knowledge whenever possible! Making IT Happen.

Leave us a message...

This site uses Akismet to reduce spam. Learn how your comment data is processed.