Você está procurando uma maneira de adicionar a coluna de ID do post à lista de posts do administrador?
Você precisa dos IDs de posts para várias finalidades, como adicionar um ID de post a algum shortcode. Normalmente, ele não está disponível com os posts e as páginas. Você pode adicionar outra coluna de administração para mostrar as informações de ID do post.
Instruções: Adicione o seguinte código ao arquivo functions.php de seu tema do WordPress.
add_filter('manage_posts_columns', 'posts_columns_id', 5); add_action('manage_posts_custom_column', 'posts_custom_id_columns', 5, 2); add_filter('manage_pages_columns', 'posts_columns_id', 5); add_action('manage_pages_custom_column', 'posts_custom_id_columns', 5, 2); function posts_columns_id($defaults){ $defaults['wps_post_id'] = __('ID'); return $defaults; } function posts_custom_id_columns($column_name, $id){ if($column_name === 'wps_post_id'){ echo $id; } }
Você também pode gostar de adicionar a coluna de ID do post à lista de posts.
Thanks this links works for me.
Hey James, you’re welcome!
This is great in it’s simplicity. But would you know how to do the same for the post excerpt? I’ve been looking a clean working solution for days with no luck….
You may be able to use this function inside the
posts_custom_id_columns()
function: https://developer.wordpress.org/reference/functions/get_the_excerpt/Can I assign custom ID to post or start id from one series.
While this is possible to do by editing the database, generally it’s not recommended to assign a custom ID to a post. Doing so incorrectly could cause problems.
Is there a way to show the IDs for only 1 post type? e.g. a custom post type?
Hi Adam,
if you want to only display it with a custom post type, remove the add_action, add_filter in the above and replace them with this eg:
add_filter(‘manage_edit-POSTTYPENAME_columns’, ‘posts_columns_id’, 5);
add_action(‘manage_posts_custom_column’, ‘posts_custom_id_columns’, 5, 2);
replace POSTTYPENAME with your post type name and your good to go.
[…] [Source] […]
[…] you’d prefer to place code in your functions file and shave off yet another plugin, try this block of code for in your functions file and you won’t need Reveal […]
For those asking how to reduce the width of the column, add the following to your functions.php file:
add_action(‘admin_head’, ‘custom_admin_styling’);
function custom_admin_styling() {
echo ”;
echo ‘th#wps_post_id{width:50px;}’;
echo ”;
}
Or whatever width you want.
Great! Like glvr, would it be possible to reduce the width of the extra column? Thanks Kevin!
[…] very useful snippet comes to you courtesy of our friend Kevin Chard of WPSNIPP.com, where they’re now rocking […]
Is there a way to reduce the width of that extra column?
[…] an easier way to find the Post ID, by adding a column in the post editor screen.Well, it seems that WP Snipp pipped me to the post as they just published a post doing exactly that. So rather than go through […]