How to add an HTML class to all image attachments on posts in Wordpress -- except homepage -


sorry length, problem simple, specific.

i'm building wordpress site automatically imports image galleries tumblr account, styles , displays them. backend finished, , need have images in posts displayed thumbnail sized links. not behaving importer (i've tried 6), have edit html display (rather images uploaded).

i have decided applying class="attachment-thumbnail size-thumbnail" on images on site (in html). have tested , open proper gallery in lightbox necessary long belong 2 classes.

i have 2 part problem.

  1. i not know php past basic syntax, , while can intuit of happening don't trust myself edit wordpress source code without understanding breaking.

from other answers i've learned should edit wp_insert_attachment() function in post.php under wp_includes/. have found function, don't know go there, not appear specific image attachments. don't want throw errors assinging image classes non-image attachments. how add 2 classes (attachment-thumbnail , size-thumbnail) post images (and images)?

  1. there single exception rule. want large image on homepage, , have not link.

it seems way handle allow page attachments handled normally, while attachments both images , attached posts should trigger this:

if [attachment image , on post, not page]:

<img src="https://whatever">

becomes

<img src="https://whatever" class="attachment-thumbnail size-thumbnail">

tl; dnr: ^^ that's need happen, in php, in right file, in wordpress ^^

thanks!

so want via php instead javascript ie jquery:

<script>     $(function() {         $("body img").addclass("attachment-thumbnail size-thumbnail");     });     </script> 

put on page or site header , add class images. can modify search filter suit.

you might need re-call lightbox initialization code too, or put before gets called initially.


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -