Black Friday sale! Get up to 25% off GP Premium! Learn more ➝

[Resolved] How to Add Title to IMG tag on Single page?

Home Forums Support [Resolved] How to Add Title to IMG tag on Single page?

Home Forums Support How to Add Title to IMG tag on Single page?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #383619
    Ralfs

    Hi,
    How to add Title tag in IMG tag on Single post page? I want right after https://puu.sh/xxIe6/27593a3458.png . I tried restore-image-title.1.5 plugin, but id did nothing. Let me know!

    #383644
    Tom
    Lead Developer
    Lead Developer

    This has actually been applied to core in the next release.

    However for now, you can do something like this: https://gist.github.com/generatepress/14851417f7bcc7620737e2e22d2c2f98

    #383681
    Ralfs

    The code you provided is just adding ALT tag, which I had already, but I wnated to add additional title tag.

    I managed to do it by editing ALT to TITLE

    add_filter(‘wp_get_attachment_image_attributes’,’tu_featured_image_alt’, 10, 2);
    function tu_featured_image_alt( $attr, $attachment ) {
    remove_filter(‘wp_get_attachment_image_attributes’,’tu_featured_image_alt’);
    $attr[‘alt’] = $attachment->post_title;
    return $attr;
    }

    changed to

    add_filter(‘wp_get_attachment_image_attributes’,’tu_featured_image_alt’, 10, 2);
    function tu_featured_image_alt( $attr, $attachment ) {
    remove_filter(‘wp_get_attachment_image_attributes’,’tu_featured_image_alt’);
    $attr[‘title’] = $attachment->post_title;
    return $attr;
    }

    And it worked. Is this good solution? I am no develoepr so not sure! πŸ™‚

    Let me know!

    #384022
    Tom
    Lead Developer
    Lead Developer

    That’s a perfect solution πŸ™‚

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.