0

I want to set the default link css class to all those images which are added to admin editor. I have found the way to add default image class with this action:

function add_image_class($class){
    $class .= ' img-frame';
    return $class;
}
add_filter('get_image_tag_class','add_image_class');

but couldn't find the way to do the same with "Link CSS Class"

Link CSS Class

  • get_link_tag_class isn't a core WordPress filter. Where did you get it? – Jacob Peattie Nov 30 '17 at 14:17
  • sorry, I have edited the question, it should be get_image_tag_class. I was able to set the image class with this filter and now i'm looking for similar solution with "link CSS Class" option – Narek Zakarian Nov 30 '17 at 14:27
0

I believe you can use wp_get_attachment_image_attributes filter here like so:

function custom_class( $attr ) {    
    $attr['class'] = 'custom-class';
    return $attr;
});
add_filter( 'wp_get_attachment_image_attributes', 'custom_class' );
  • thank you but this doesn't work. Maybe this will work on featured images, but not the images which are uploaded in editor – Narek Zakarian Dec 1 '17 at 7:29

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.