Title image tags not appearing on your Visual Composer site? Here’s the fix…

by Sam Davis
If you create your WordPress websites using Visual Composer, join the club – it’s fantastic. I love the rigidity, the feature-packed interface, the ease of creating a stylish responsive design, plus the support for plugins-a-plenty. One of my clients recently however noticed a glitch – the image tooltip no longer appears when you hover over an image!
When you upload a photo to the WordPress media library, regardless of whether you fill out the Title, Alt text, Caption, and Description, when it comes to adding a single image in Visual Composer, the title tag simply doesn’t show up in the code.
Whilst some people think that it is the Alt tag that is responsive for the tooltip, it is actually the Title tag that does it – and whilst the former does appear in the code, the latter – which is responsible for the tooltip – does not. It should be remembered that an an Alt tag is primarily used for SEO whereas a Title tag is not. If an image does not appear on your website, they will see the Alt tag only, whereas the Title tag is can be designed to describe the image content with complimentary text.
Regardless, if you’re a stickler for making sure everything is done by the book, you’ll undoubtedly want your title tags there, so adding the following piece of code to your themes functions.php file will sort the problem out.
function show_title_tag( $attr, $attachment = null ) {
$img_title = trim( strip_tags( $attachment->post_title ) );
$attr['title'] = $img_title;
$attr['alt'] = $img_title;
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes','show_title_tag', 10, 2 );
Hope this helps! If this piece of advice proved useful for you, then please consider posting a comment on the article to let me know that it worked! Similarly, if you’d like me to action this fix for you on your website, then I can do this for you – just buy me a couple of beers to say thanks!
GET IN TOUCH IF YOU NEED ANY HELP!
Sam Davis
I am fanatical about providing useful web experiences, via bespoke websites which engage, inform and entertain. I have been making websites since a young age, and am a keen supporter of AFC Bournemouth.




