Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1286012

    on gallery images with link there are some additional infos on the anchor itself and on the image too.
    The galleries got that $lightbox_title with cases caption / description etc – the img tag itself got the title tag – and the anchors that lightbox_title.
    That is very nice to have – because we can influence on what to show in the lightbox markup.
    on images alb – the anchor got nothing in additon and the image-tag got title.
    on images placed in text blocks – there is even no title on the image-tag.
    maybe on next update there will be something similar to gallery to have a lightbox-title inside the anchor.

    #1288013

    Hey Guenter,

    If I follow your idea it would be necessary to extend the metadata of an image (in WP media popup attachment details sidebar) with:

    • Lightbox Title
    • Lightbox Description

    and add the metadata info to all ALB img tags (like alt, title, caption, desc, lightbox-title, lightbox-desc) ?

    Best regards,
    Günter

    #1288320

    you can see what i mean here on that page: https://webers-testseite.de/images/
    An image placed in a text-block via Media-Library insertion does not have title attribute ( right side an image alb with title – and the option to give custom alt/title attributes to it ) – but that is not what i want. Why does the left image got no title if it has one ( see right flowers )

    #1288331

    Hi,

    The “media” button in tinyMCE is standard WP. Actually a WP bug I would say.

    When you switch from visual to text mode you see the generated HTML by WP containing the alt but not the title. Enfold does not hook in this.

    Only way I see is try to add the image shortcode manually – but keep an eye on the layout, that it gets not broken.

    Best regards,
    Günter

    #1288429

    yes that was already clear to me that this is not due to Enfold, I thought you had a hint or knowledge about how to extend the tinyMCE so that it automatically reads and uses the attachment title and alt attributes.
    I’m going to start looking for it myself now – and I’ll report back.

    #1288445

    Hi,

    Sorry, but no hint for that problem.

    Instead of hacking tinyMCE – wouldn’t it be easier to switch to text mode and add the attributes manually to HTML? Depends how often you need it.

    But thanks in advance for reporting back when you have found some solution.

    Have a great day.

    Best regards,
    Günter

    #1288653

    Depends how often you need it.

    If you take over an older WordPress installation and you want to change the style to Enfold, and the posts (blog) are all created with the Classic Editor which contains several 100 images, the manual method is an option but should be avoidable if at all possible.
    __________
    this does not solve my issue above, but probably explains why there are no more title tags on the images
    i found this filter: image_send_to_editor – and i can influence the output then on the inserted images in the textblock – but the title attribute is always missing! ( Allthough it is in the filter

    apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt, $rel );
    

    edit: aha – on wordpress/ wp-admin / includes / ajax-actions.php line: 3251:

    $title = ''; // We no longer insert title tags into <img> tags, as they are redundant.
    
    • This reply was modified 3 years, 9 months ago by Guenni007.
    #1288717

    Hi,

    Good catch with the filter.

    I think we should add the filter to core that we add the title to new added images (with an option in SEO tab to disable this).

    But for existing images in already existing pages (where only the img tag html exists and probably no reference to the attachment id ) it will be difficult.

    Best regards,
    Günter

    #1288788

    First i thought i can manage it for newly inserted images this way.

    function html_insert_image( $html, $id, $caption, $title, $align, $url, $size, $alt ) {
    	$src  = wp_get_attachment_image_src( $id, $size, false );
    	$html = "<figure id=\"post-$id media-$id\" class=\"align-$align\">";
    		if ( $url ) {
    		$html .= "<a href=\"$url\" class=\"image-link\"><img src=\"$src[0]\" title=\"$title\" alt=\"$alt\" /></a>";
    		} else {
    		  $html .= "<img src=\"$src[0]\" title=\"$title\" alt=\"$alt\" />";
    		}
    		if ( $caption ) {
    		  $html .= "<p class='wp-caption-text'>$caption</p>";
    		}
    	$html .= "</figure>";
    	return $html;
    	}
    add_filter( 'image_send_to_editor', 'html_insert_image', 10, 9 );

    BUT: as mentioned above that line in ajax-actions.php – the title tag isn’t supported anymore for images

    Maybe the people at WordPress will reconsider this decision.
    even if:

    For both accessibility and search engine optimization (SEO), alt text is more important than title text. This is why we strongly recommend including alt text for all your images.

    #1288932

    Hi,

    You need to query the image title in your function:

    $title = get_the_title( $id );

    And i would not rebuild the html code in this filter but just insert the title attribute. My final solution would be:

    
    function html_insert_image( $html, $id, $caption, $title, $align, $url, $size, $alt ) 
    {
    	$html = str_replace( '<img ', '<img title="' . esc_attr( get_the_title( $id ) ) . '" ' , $html );
    	return $html;
    }
    
    add_filter( 'image_send_to_editor', 'html_insert_image', 10, 8 );
    

    Best regards,
    Günter

    #1289009

    yes – thats it ( for newly added images )
    and you see the advantage of heaving this if there is an image with lightbox – it has the title in the bottom-bar: https://webers-testseite.de/images/ (right-side image)

    by the way : wordpress / wp-includes / kses.php / lines227ff:

    'img'        => array(
    	'alt'      => true,
    	'align'    => true,
    	'border'   => true,
    	'height'   => true,
    	'hspace'   => true,
    	'loading'  => true,
    	'longdesc' => true,
    	'vspace'   => true,
    	'src'      => true,
    	'usemap'   => true,
    	'width'    => true,
    ),

    not title anymore as allowed tags

    #1289593

    Hi,

    We added a slightly modified filter to our docu:

    Best regards,
    Günter

    #1290057

    Thanks Günter – that should be discussed for now. I haven’t quite been able to understand their (WordPress) reasoning yet (it’s probably also about the screen reader functionality); maybe WordPress will reconsider putting the title back.
    Can be closed

    #1290109

    Hi,

    Have a great day !

    Best regards,
    Günter

Viewing 14 posts - 1 through 14 (of 14 total)
  • The topic ‘Images with link’ is closed to new replies.