0

How to add $term->name (slug) into custom column cells as the file name?

$columns = '<img src="SLUG_NAME.jpg">';



function custom_column_header( $columns ){
        $columns['image'] = 'Image';
        return $columns;
    }
    add_filter( "manage_edit-genre_columns", 'custom_column_header', 10);

    function custom_column_content( $value, $column_name, $term_id ){
        if ($column_name === 'image') {
            $columns = '<img src="SLUG_NAME.jpg">';
        }
        return $columns;
    }
    add_action( "manage_genre_custom_column", 'custom_column_content', 10, 3);
0

You can use get_term_field() like this:

if ($column_name === 'image') {
    $slug = get_term_field( 'slug', $term_id );
    $columns = '<img src="' . $slug . '.jpg">';
}

Or get_term():

if ($column_name === 'image') {
    $term = get_term( $term_id );
    $columns = '<img src="' . $term->slug . '.jpg">';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.