• Resolved coldpumpkin

    (@coldpumpkin)


    Hello there.

    When we’re inserting an image to a post, by clicking the “Add Media” button, WordPress generates a certain code, being:

    <a href="image_url"><img src="image_url" alt="image_name" width="image_width" height="image_height" class="image_class" /></a>

    Question here is – how to change the way the code is generated? What if I want to add attributes to the <a> tag? And what if I don’t want some of those attributes of the <img> tag?

    Thanks in advance for your answers!

Viewing 4 replies - 16 through 19 (of 19 total)
  • Thread Starter coldpumpkin

    (@coldpumpkin)

    I know it can be used for usability purposes but for now I’ll exclude it. The href and the src are supposed to be the same, yes.

    Thread Starter coldpumpkin

    (@coldpumpkin)

    nickohm you still there?

    nickohrn

    (@nickohrn)

    Sorry – I got caught up in client work. Anyways, here’s something that should work for you:

    function filter_image_send_to_editor($html, $id, $caption, $title, $align, $url, $size, $alt) {
      $html = sprintf('<a class="fancybox-img" href="%1$s"><img alt="%2$s" src="%1$s" /></a>', esc_attr(esc_url($url)), esc_attr($title));
    
      return $html;
    }
    add_filter('image_send_to_editor', 'filter_image_send_to_editor', 10, 8);
    Thread Starter coldpumpkin

    (@coldpumpkin)

    It’s ok, I’m sorry too, I just thought you didn’t notice my reply.

    That works like a charm and I can’t thank you enough ?? This nooblet cheers you!

Viewing 4 replies - 16 through 19 (of 19 total)
  • The topic ‘Change generated HTML code from "Add Media" button’ is closed to new replies.