• I want my in-image ads to appear only on the first long vertical images of my blog posts. I need to add a unique image class to the first images, but I don’t know how to do this or what code to use.

    Someone gave me this css code:

    jQuery(function($) {
    $(“article img:first-of-type”).addClass(“unique”);
    });

    I added it to additional CCS in my WordPress customization.

    The blog I need help with is lifeismessyandbrilliant.com.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator t-p

    (@t-p)

    Moderator bcworkz

    (@bcworkz)

    The code you were given is jQuery script, not CSS. t-p’s link is to add a class to all images, so it would need to be adapted to work for you. It appears your jQuery code might do the job if it were applied properly.

    It appears you are using a code insertion plugin, I suggest you use it to add your jQuery. Adding to the footer should be fine.

    Thread Starter Jenniffer

    (@jeffinner07)

    Just to make sure, the JQuery that I was given should work as long as I place it in the footer?

    If I put it in the additional CCS from the customization tab in wordpress it won’t work the same way as in the footer?

    If I put it in the additional CCS from the customization tab in wordpress it won’t work the same way as in the footer?

    Additional CSS is for CSS, not JavaScript, so no, it won’t work. You need to output in the footer inside <script></script> tags:

    <script>
    jQuery(function($) {
    $(“article img:first-of-type”).addClass(“unique”);
    });
    </script>
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to add unique image class to WordPress?’ is closed to new replies.