-
AuthorPosts
-
March 6, 2021 at 9:28 am #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.March 13, 2021 at 3:00 pm #1288013Hey 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ünterMarch 15, 2021 at 3:42 pm #1288320you 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 )March 15, 2021 at 4:07 pm #1288331Hi,
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ünterMarch 16, 2021 at 9:08 am #1288429yes 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.March 16, 2021 at 10:25 am #1288445Hi,
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ünterMarch 17, 2021 at 8:39 am #1288653Depends 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 filterapply_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, 8 months ago by Guenni007.
March 17, 2021 at 12:44 pm #1288717Hi,
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ünterMarch 17, 2021 at 9:20 pm #1288788First 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.
March 18, 2021 at 11:40 am #1288932Hi,
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ünterMarch 18, 2021 at 3:44 pm #1289009yes – 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
March 22, 2021 at 11:26 am #1289593March 24, 2021 at 10:55 am #1290057Thanks 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 closedMarch 24, 2021 at 1:43 pm #1290109 -
AuthorPosts
- The topic ‘Images with link’ is closed to new replies.