0

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. – Arsalan Mithani Feb 22 '17 at 16:57
  • I know but I need to get the value that was added to the "Image CSS Class" field. – Taras Dashkevych Feb 22 '17 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? – Arsalan Mithani Feb 22 '17 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. – Taras Dashkevych Feb 22 '17 at 17:17
  • you got your answer? – Arsalan Mithani Feb 22 '17 at 17:19
0

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, privacy policy and cookie policy

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