Está procurando uma maneira de adicionar uma nova coluna à tela de posts com um campo de entrada contendo o shortlink? Embora provavelmente exista um plug-in para isso, criamos um trecho de código rápido que você pode usar para adicionar uma coluna de postagem administrativa com wp_get_shortlink
no WordPress.
Instruções:
Tudo o que você precisa fazer é adicionar esse código ao arquivo functions.php do seu tema ou em um plugin específico do site:
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; }
Observação: Se esta é a primeira vez que você adiciona trechos de código no WordPress, consulte nosso guia sobre como adicionar corretamente trechos de código no WordPress, para não danificar seu site acidentalmente.
Se você gostou desse snippet de código, considere dar uma olhada em nossos outros artigos no site, como: 9 melhores plug-ins de help desk do WordPress e como configurar o rastreamento de downloads no WordPress com o 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.