• Hi.

    Is it possible, for when you insert an image into a post, to automatically assign it a CSS class? Would just seem a little simpler than inserting the image, closing the media uploader, clicking on the image proper then navigating to advanced settings to change the class.

    The reason being is I want to apply some custom CSS formatting to certain images in posts.

    I imagine I would have to do this via the functions.php template (correct me if I’m wrong), but I’m not sure where to go after that. If anyone has any tips and/or solutions that would be great!

Viewing 3 replies - 1 through 3 (of 3 total)
  • DigitalSquid

    (@twelvefootsnowman)

    Each post gets it’s own class automatically – eg: postid-1, postid-2, etc…

    So if you know the post ID and there’s only one image in the post you could use .postid-1 img to select it with CSS.

    Thread Starter Christopher

    (@freestylemedia)

    I was just about to say I want it for all posts (as it’s a photo gallery), but then I’ve just thought that I can give all posts the same class and go from there!

    Well, hopefully, anyway :p

    Hi,

    Find out what your posts are wrapped in (should be content or something similar) Then maybe….

    ./#content img {
    >YOUR STYLE<
    }

    Let me know if it worked please or post the url (not sure if wordpress allows this) and I’ll have a look.

    Lou

    **EDIT**
    Just noticed you didn’t want the class for ALL images so just define a div class with styling in your stylesheet and then wrap each picture in the that div class individualy.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Default CSS class for image in post’ is closed to new replies.