Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Johan

Show post ID in the title column

Hi, because I am not using the title field for my custom posts I would like to replace the post titles with the post ID’s. Is there an easy way to do this?

6 years, 4 months ago
Jesper
Developer

Hi Johan,

Admin Columns itself offers no quick feature for this, but you can easily achieve it by using a built-in WordPress filter. Applying the filter the_title selectively should work.


add_filter( 'the_title', 'myplugin_overview_post_title', 10, 2 );

function myplugin_overview_post_title( $title, $postid ) {
	global $pagenow;

	$post_type = 'my-custom-post-type';

	// Only use the ID in the overview for the specified custom post type
	if ( $pagenow == 'edit.php' && ! empty( $_GET['post_type'] ) && $_GET['post_type'] == $post_type ) {
		return $postid;
	}

	return $title;
}

Best,
Jesper

6 years, 3 months ago

You must be logged in to reply to this topic.