Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to be able to add a <span></span> around every image that gets posted. How will I be able to do this?

share|improve this question
    
You could do that with Jquery. See this thread for some guidance: stackoverflow.com/questions/3987422/jquery-add-tag-a-around-img –  Michelle Aug 24 '11 at 18:18
    
do you want to do this when you save the post to the database, or when you show the post? –  Michael Aug 24 '11 at 18:18
    
I would prefer not using jQuery to achieve this... I looked into this thread, but was unable to get this to work even after editing the core files: wordpress.stackexchange.com/questions/20998/… I want this to show when it is rendered on the page. The tags are used for styling and I do not want to add the <span> tag in the html editor every time a new image is added. –  yookd Aug 24 '11 at 18:22
    
Additional clarification: When I create a new post and upload an image, a span tag should automatically be wrapped around the image. Ideally, I want to stay away from adding it in the embedded html editor. –  yookd Aug 24 '11 at 21:32
    
<span> is typically considered an inline element so you might not want to wrap all your images in such tags. If you want to achieve some specific effect, consider defining a shortcode for the purpose. –  Raphael Feb 9 '12 at 19:07

1 Answer 1

try to add a filter function to functions.php of your theme;

example:

add_filter('the_content', 'alc_image_spanner');

  function alc_image_spanner($text) {
    $text = preg_replace_callback("#<img(.*?)>#is", create_function('$matches', 'return "<span><img".$matches[1]."></span>";'), $text);
    return $text;
  }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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