Question:

Resize $term attachment using url

Piper: 18 January 2022

I'm using this plugin (https://it.wordpress.org/plugins/wp-custom-taxonomy-image/) for attaching an image to a custom taxonomy. The plugin's function returns the attached term's image as following:

function get_wp_term_image($term_id){
    return get_option('_category_image'.$term_id);  
}

It works fine but I'd like to resize the returned image because I'm using it in a page displaying all taxonomy categories with relative thumbs. It means that if you upload a big image you get that and the page becomes very heavy to load. I've tried to add this hook without success, in my page loop:

$term_id = $term->term_id;
if (function_exists('get_wp_term_image'))
   {
    $meta_image = get_wp_term_image($term_id);
    //tried this
    $term_image = wp_get_attachment_image_src($term_id, 'smalltax');
    //and this
    $image_id = attachment_url_to_postid($meta_image);
    //no success
    }
  • In the first case I've assumed that wp_get_attachment_image_src hook considers the attachment from whatever id but I was wrong.
  • In the second case I've thought to get the $image_id with the attachment_url_to_postid hook and then resize with some other tweaking.

Can you provide a solution? Even modifying the plugin itself. Thanks.

Answer:
Maria: 18 January 2022

Some passing by can eventually find an answer to this question here (https://stackoverflow.com/questions/38397304/wordpress-resize-term-attachment-using-url/38397424?noredirect=1#comment64203794_38397424). Same community but more proactive there. Weird.