• I want to add a column in the pages page with the page template name for every page. I manage to add a column to the pages page but i don’t know how to bind the page template name to the column.
    This is the code for adding the page template column in functions.php file .

    function my_custom_pages_columns( $columns ) {
    
    	$myCustomColumns = array(
    		'templatename' => __( 'Template')
    	);
    	$columns = array_merge( $columns, $myCustomColumns );
    
    	return $columns;
    }
    add_filter( 'manage_pages_columns', 'my_custom_pages_columns' );

    I would appreciate your help

Viewing 1 replies (of 1 total)
  • Try this:

    function my_custom_pages_columns( $columns ) {
     	$myCustomColumns = array(
    		'template' =>  __( 'Template')
    	);
    	$columns = array_merge( $columns, $myCustomColumns );
    	return $columns;
    }
    function custom_admin_css() {
    echo '<style type="text/css">
    	td.column-template { width: 150px; }
    	th.column-template { width: 150px; }
    </style>
    ';
    }
    
    function custom_page_column_content( $column_name, $post_id ) {
    	if ( $column_name == 'template' ) {
    		$page_template = get_field( '_wp_page_template' );
    		if ( $page_template) {
    			$page_template = str_replace ( "default" , " " , $page_template );
    			$page_template = str_replace ( "template-" , "(" , $page_template );
    			$page_template = str_replace ( ".php" , ")" , $page_template );
    			echo $page_template;
    		}
    	}
    }
    
    add_action('admin_head', 'custom_admin_css');
    add_filter( 'manage_pages_columns', 'my_custom_pages_columns' );
    add_action( 'manage_pages_custom_column', 'custom_page_column_content', 10, 2 );

    The only thing is the get_field() call may not work with custom fields, I don’t know.

Viewing 1 replies (of 1 total)
  • The topic ‘Adding column to pages page with page template name’ is closed to new replies.