By default, WordPress allows to add an extra class to the image via Advanced Options section: https://cloudup.com/cBR2yxukXm9

If I know the image (attachment) ID then how can I get this value?

I tried get_post_meta function but it did not show me that extra class. So, I am assuming I need to use an another function to retrieve the value.

  • get a class? if you just want to apply your style then you should simply do it as : .custom-class { your styles here } in your style file. Commented Feb 22, 2017 at 16:57
  • I know but I need to get the value that was added to the "Image CSS Class" field.
    – user85513
    Commented Feb 22, 2017 at 17:01
  • i think your class will be applied/called when you add this image anywhere, why you want to get the value? what you are trying to do? Commented Feb 22, 2017 at 17:02
  • Correct. This class will be added to img tag. I want to use this class in the caption (figure tag) shortcode as well.
    – user85513
    Commented Feb 22, 2017 at 17:17
  • you got your answer? Commented Feb 22, 2017 at 17:19

1 Answer 1


The Advanced Options section you are talking about the one in the Image Details, the modal that shows when clicking here:

enter image description here

that part is tinyMCE, its part of the tinyMCE editor, none of these fields are being saved in the WordPress database:

enter image description here

this is just and interface to gather data that will be set in the <img> tag, it uses JavaScript, the interface is populated when you click in the image if there is any attribute and/or data that was previously set there.

so you cant use WordPress functions to get those classnames.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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