Are you looking for a way to add a new column to the posts screen with an input field containing the shortlink? While there’s probably a plugin for this, we have created a quick code snippet that you can use to add admin post column with wp_get_shortlink
in WordPress.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
add_filter( 'manage_posts_columns', 'shortlink_add_column' ); add_action( 'manage_posts_custom_column', 'shortlink_add_value', 10, 2 ); function shortlink_add_column($cols) { $cols['shortlink'] = __('Shortlink'); return $cols; } function shortlink_add_value($column_name, $post_id) { if ( 'shortlink' == $column_name ) { echo '<input type="text" value="'.wp_get_shortlink($post_id).'" onclick="this.focus(); this.select();" />'; } } add_filter( 'manage_edit-post_sortable_columns', 'shortlink_sortable_column' ); function shortlink_sortable_column( $columns ) { $columns['shortlink'] = 'Shortlink'; return $columns; }
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 9 best WordPress help desk plugins and how to set up download tracking in WordPress with Google Analytics.
I noticed this column works on posts but not on custom post types. Any ideas?
Hi Clifford, you can do the following for example.
manage_edit-${post_type}_columns
For a more detailed overview the codex has a working sample.
http://codex.wordpress.org/Plugin_API/Action_Reference/manage_$post_type_posts_custom_column
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
The original snippet’s “Shortlink” column displays as one of the CPT’s columns. It’s just that nothing displays. I verified with echo wp_get_shortlink(‘13715’); that that CPT post has a shortlink.
let me take a look and post something for you.
Can this also support bit.ly links?
As of right now it just uses the wordpress short url’s although I’m sure it could be setup to work with bitly as well. I take a look into it and see what I can come up with.