Skip to content

Instantly share code, notes, and snippets.

@mmarj
Forked from gmmedia/functions.php
Created August 12, 2022 17:54
Show Gist options
  • Save mmarj/f8ddf5a89eac66f00d36eb8b9374aaca to your computer and use it in GitHub Desktop.
Save mmarj/f8ddf5a89eac66f00d36eb8b9374aaca to your computer and use it in GitHub Desktop.

Revisions

  1. @gmmedia gmmedia revised this gist Feb 9, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion functions.pnp
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    /**
    * Add featured image column to WP admin panel - posts AND pages
    * See: https://j0e.org/featured-image-admin/
    * See: https://bloggerpilot.com/featured-image-admin/
    */

    // Set thumbnail size
  2. @gmmedia gmmedia revised this gist Mar 23, 2021. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions functions.pnp
    Original file line number Diff line number Diff line change
    @@ -10,20 +10,20 @@ add_image_size( 'j0e_admin-featured-image', 60, 60, false );
    add_filter('manage_posts_columns', 'j0e_add_thumbnail_column', 2);
    add_filter('manage_pages_columns', 'j0e_add_thumbnail_column', 2);
    function j0e_add_thumbnail_column($j0e_columns){
    $j0e_columns['j0e_thumb'] = __('Image');
    return $j0e_columns;
    $j0e_columns['j0e_thumb'] = __('Image');
    return $j0e_columns;
    }

    // Add featured image thumbnail to the WP Admin table.
    add_action('manage_posts_custom_column', 'j0e_show_thumbnail_column', 5, 2);
    add_action('manage_pages_custom_column', 'j0e_show_thumbnail_column', 5, 2);
    function j0e_show_thumbnail_column($j0e_columns, $j0e_id){
    switch($j0e_columns){
    case 'j0e_thumb':
    if( function_exists('the_post_thumbnail') )
    echo the_post_thumbnail( 'j0e_admin-featured-image' );
    break;
    }
    switch($j0e_columns){
    case 'j0e_thumb':
    if( function_exists('the_post_thumbnail') )
    echo the_post_thumbnail( 'j0e_admin-featured-image' );
    break;
    }
    }

    // Move the new column at the first place.
    @@ -45,5 +45,5 @@ function j0e_column_order($columns) {
    // Format the column width with CSS
    add_action('admin_head', 'j0e_add_admin_styles');
    function j0e_add_admin_styles() {
    echo '<style>.column-j0e_thumb {width: 60px;}</style>';
    echo '<style>.column-j0e_thumb {width: 60px;}</style>';
    }
  3. @gmmedia gmmedia created this gist Mar 23, 2021.
    49 changes: 49 additions & 0 deletions functions.pnp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    /**
    * Add featured image column to WP admin panel - posts AND pages
    * See: https://j0e.org/featured-image-admin/
    */

    // Set thumbnail size
    add_image_size( 'j0e_admin-featured-image', 60, 60, false );

    // Add the posts and pages columns filter. Same function for both.
    add_filter('manage_posts_columns', 'j0e_add_thumbnail_column', 2);
    add_filter('manage_pages_columns', 'j0e_add_thumbnail_column', 2);
    function j0e_add_thumbnail_column($j0e_columns){
    $j0e_columns['j0e_thumb'] = __('Image');
    return $j0e_columns;
    }

    // Add featured image thumbnail to the WP Admin table.
    add_action('manage_posts_custom_column', 'j0e_show_thumbnail_column', 5, 2);
    add_action('manage_pages_custom_column', 'j0e_show_thumbnail_column', 5, 2);
    function j0e_show_thumbnail_column($j0e_columns, $j0e_id){
    switch($j0e_columns){
    case 'j0e_thumb':
    if( function_exists('the_post_thumbnail') )
    echo the_post_thumbnail( 'j0e_admin-featured-image' );
    break;
    }
    }

    // Move the new column at the first place.
    add_filter('manage_posts_columns', 'j0e_column_order');
    function j0e_column_order($columns) {
    $n_columns = array();
    $move = 'j0e_thumb'; // which column to move
    $before = 'title'; // move before this column

    foreach($columns as $key => $value) {
    if ($key==$before){
    $n_columns[$move] = $move;
    }
    $n_columns[$key] = $value;
    }
    return $n_columns;
    }

    // Format the column width with CSS
    add_action('admin_head', 'j0e_add_admin_styles');
    function j0e_add_admin_styles() {
    echo '<style>.column-j0e_thumb {width: 60px;}</style>';
    }