• Hi!, I am wondering if it is possible to add a class name to the image with the same name (or names if it has multiple categories assigned) of its assigned category.
    I think it would be very useful. Can you point me in the right direction to achieve this?
    Thank you in advance

Viewing 1 replies (of 1 total)
  • Thread Starter marianogi

    (@marianogi)

    Here I found something:

    http://wordpress.stackexchange.com/a/156576/26350

    I use the “get_image_tag_class” filter, but I use the get_the_term function to get the categories. Here is my code:

    add_filter( 'get_image_tag_class', 
        function( $class, $id, $align, $size )
        {
            $idiomas = get_the_terms($id,'category');
    		if ( is_array($idiomas) )
    		{
    			foreach( $idiomas as $idioma ) {
    
    				$class .= ' ' . $idioma->slug;
    			}
    		}
            return $class;
        }
    , 10, 4 );
Viewing 1 replies (of 1 total)
  • The topic ‘img class from category name’ is closed to new replies.