I added a custom html to insert captions/date under pictures, but after its inserted in the backoffice the text i right after it gets the same font-size and marging, cant get to the default post font size.

Code:

    function include_image_credits( $html, $id, $alt, $title, $align, $size ) {
        $post = get_post( $id );
        $caption = wp_get_attachment_caption( $id );
        $get_img_info = wp_get_attachment_metadata( $id );
        $img_width = $get_img_info['width'];
        $credits = get_post_meta( $id, 'photographer_name', true );
        $date = get_post_meta( $id, 'photo_date',true );
        $styles = '';
    if ( $img_width ) {
            $styles = 'style="width: ' . (int) $img_width . 'px" ';
    }

    if ( isset( $credits ) && empty( $caption ) && '' !== $credits || isset( $date ) &&  empty( $caption ) && '' !== $date ) {
            $html .= '<div id="teste" class="credits__date"' . $styles . '>' ;
            $html .= '<span class="caption__source">' . $credits . '</span> ';
            $html .= '<span class="caption__date">' . $date . '</span> ';
            $html .= '</div>';
    }
    return $html;
}
add_filter( 'get_image_tag', 'include_image_credits', 10, 6 );

Any ideia how i can fix this?

Read more here: break out of custom html


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: