WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There is a button called "get shortlink" for wordpress builtin post type & pages. If we click on it we can get wp.me shortend url for that particular post

This can also be got using the function wp_get_short_link() in the template file.

However this doesn't seems to work for the custom post type.

I used the following code to get shortlink to work on custom post type, but it outputs the default shortlink which is www.mysitename.com/?p=234, but i require wp.me shortlink for my custom post type.

if( !function_exists( 'my_theme_cpt_shortlinks' ) ) {
 * Allow shortlinks to be retrieved for pages and custom post types
function my_theme_cpt_shortlinks( $shortlink, $id, $context, $allow_slugs=true ) {
 * If query is the context, we probably shouldn't do anything
if( 'query' == $context )
    return $shortlink;

$post = get_post( $id );
$post_id = $post->ID;

 * If this is a standard post, return the shortlink that was already built
if( 'post' == $post->post_type )
    return $shortlink;

 * Retrieve the array of publicly_queryable, non-built-in post types
$post_types = get_post_types( array( '_builtin' => false, 'publicly_queryable' => true ) );
if( in_array( $post->post_type, $post_types ) || 'page' == $post->post_type )
    $shortlink = home_url('?p=' . $post->ID);
    //$shortlink =  wp_get_shortlink($post->ID);

return $shortlink;

add_filter( 'get_shortlink', 'my_theme_cpt_shortlinks', 10, 4 );

Is there any way to modify the above function to get wp.me shortlink for the custom post type instead of default shortlink?

share|improve this question
Please don't cross post. Generally, WordPress questions should be asked here, not on SO – shea Mar 6 '13 at 11:41
You should have a look at the shortlink functions included in Jetpack: plugins.svn.wordpress.org/jetpack/trunk/modules/shortlinks.php – shea Mar 6 '13 at 11:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.