• So I’m trying to wrap media images published in a post into a custom div, that is also wrapped in a link tag that has the permalink of the media image as it’s href. Here’s the filter that I’ve made so far.

    add_filter( 'image_send_to_editor', 'wp_image_wrap_init', 10, 8 );
    function wp_image_wrap_init( $html, $id, $caption, $title, $align, $url, $size, $alt ) {
        return '
    
         <div id="js-simple-lightbox" class="cbp">
            <div class="cbp-item">
                <a href="'. $url . '" data-title="Workout Buddy<br>by Tiberiu Neamu">
                  <div class="cbp-caption-defaultWrap">'. $html .'</div>
                            <div class="cbp-caption-activeWrap">
                                <div class="cbp-l-caption-alignLeft">
                                    <div class="cbp-l-caption-body">
                                        <div class="cbp-l-caption-title">Workout Buddy</div>
                                        <div class="cbp-l-caption-desc">by Tiberiu Neamu</div>
                                    </div>
                                </div>
                            </div>
                  </a>
                </div><!-- end cbp-item -->
            </div>';
    
    }

    It works in that it shows the divs and it also wraps the image within those divs, but it doesn’t display the link tag with the data-title attribute assigned to it, or show the image url at all when pulling the content. Is there a work around for this? If I activate the ‘Link To’ when editing the image in the post it’ll wrap just the image in a link, but I need the link to also enclose a couple of divs.

  • The topic ‘Display Post Image Wrapped in Div, Inside Link Tag’ is closed to new replies.