Vous cherchez un moyen d’ajouter la colonne ID de l’article à la liste des articles de l’administrateur ?
Vous avez besoin de l’ID des articles pour de multiples raisons, comme l’ajout d’un ID d’article à un shortcode. Normalement, ce n’est pas disponible avec les articles et les pages. Vous pouvez ajouter une autre colonne d’administration pour afficher l’information sur l’ID de l’article.
Instructions : Ajoutez le code suivant au fichier functions.php de votre thème 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; } }
Vous pouvez également apprécier l’ajout de la colonne ID de l’article à la liste des articles.
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 […]