Written by
David Artiss. Published 11 months, 2 weeks ago. Last modified 2 weeks, 4 days ago. In categories
Wordpress.
Many WordPress functions have a standard version which outputs the results directly and an additional version prefixed with get_ that returns the output – useful for adding to a string and manipulating before output.
One such exclusion is the_shortlink, which returns a short link to any page or post – there is no get_the_shortlink, so many people have to resort to just outputting the result in a FORM field for people to cut & paste. However, here is a quick way to add the capability to your blog – simply add the following 5 lines to your theme’s function.php file…
function get_the_shortlink() {
$post_id = get_the_ID();
if ($post_id!="") {$shortlink=home_url()."/?p=".$post_id;} else {$shortlink="";}
return $shortlink;
}Or, in one line…
function get_the_shortlink() {if (get_the_ID()!="") {return home_url()."/?p=".get_the_ID();} else {return;}}Now you just need to call get_the_shortlink() from within your WordPress loop and it will return the shortlink URL.
Unlike the_shortlink it doesn’t accept any parameters, but this is a quick and simple solution.


Written by
David Artiss. Published 11 months, 3 weeks ago. In categories
News,
Web Development,
Wordpress.
WP README Parser version 1.1 has been released with the following changes…
- Improved code display – particularly code multi-lines
- Fixed a file fetching bug
- Added a new option to suppress specific lines of output
Full details, including a download link, are available on the plugin page.


Written by
David Artiss. Published 11 months, 3 weeks ago. In categories
Web Development,
Wordpress.
Today I’ve launched a new WordPress plugin – WP Relative Date.
This provides a much needed improvements to WordPress’ ability to display relative dates (e.g. “This post was added 4 days ago.”) A simple change to your theme code and you can benefit from improved levels of reporting (WordPress, for instance, only shows a maximum of months, hence a post that is a number of years old will display as a large number of months instead).
I wrote this as part of the recent site re-vamp and initially included the functionality within my functions.php file. In the end I converted it to a separate plugin, however, and updated it to be of release quality.
More details and download instructions are on the plugin’s dedicated page.

