post_type; } /** * Adds Slug column to Posts list column * * @param array $defaults An array of column names */ public function WPASC_posts( $defaults ) { $defaults['wpasc-slug'] = __( 'URL Path', 'admin-slug-column' ); return $defaults; } /** * Gets the post info from get_post function and displays the slug and/or path * * @param string $column_name Name of the column * @param int $id post id * * @see https://developer.wordpress.org/reference/functions/get_post/ */ public function WPASC_posts_data( $column_name, $id ) { if ( $column_name == 'wpasc-slug' ) { $post_info = get_post( $id, 'string', 'display' ); $post_slug = $post_info->post_name; $post_type = $post_info->post_type; $post_status = $post_info->post_status; if ( $post_type === 'page' ) { // Get full permalink but remove domain.tld $post_slug = str_replace( home_url(), '', get_permalink( $id ) ); } if ( $post_type === 'post' ) { // Add root & trailing slash to slug only for published or scheduled pages; ignore drafts if ( $post_status === 'publish' || $post_status === 'future' ) { $post_slug = '/' . $post_slug . '/'; } } // Echo out what we've got echo esc_attr( $post_slug ); } } } $WPAdminSlugColumn = new WPAdminSlugColumn();