WordPress.org

Ready to get started?Download WordPress

Forums

Add/set class to all post images (2 posts)

  1. Tara Rotten
    Member
    Posted 2 years ago #

    Hello,

    I want to add an image class to all images uploaded in posts.
    At the moment my img code looks like this

    <img class="alignleft size-thumbnail wp-image-46" width="400" height="598" alt="" src="http://mysite.com/minibook/wp-content/uploads/2011/07/tumblr_loaiyhK8vu1qdu3vi-400x598.png" title="Homme Japan">

    is there a way to set the image class to a default so all my post images have the same class?

  2. digitalrenewal
    Member
    Posted 2 years ago #

    im not sure if this is what youre looking for, but it worked for me...

    I needed to wrap all of my images with a class to trigger a javascript workaround. since div didnt work in this example, i used span and it worked.

    added this to functions.php

    // WRAP UPLOADED IMAGES IN CLASS
    if(is_admin()){
    
      add_filter('image_send_to_editor', 'wrap_my_div', 10, 8);
    
      function wrap_my_div($html, $id, $caption, $title, $align, $url, $size, $alt){
        return '<span class="rame-img" id="mydiv-'.$id.'">'.$html.'</span>';
      }
    }

    code came from here

Topic Closed

This topic has been closed to new replies.

About this Topic