WordPress.org

Ready to get started?Download WordPress

Forums

Stripping the title attribute from images (3 posts)

  1. ncott
    Member
    Posted 3 years ago #

    Hi All,

    So, I'm basically just trying to strip the title attribute which is returned by default from all of the images on my site (including those outside of the_content), and I'm drawing a blank -

    Due to some reading around, I suspect that I have to filter
    wp_get_attachment_image_attributes (see here) in functions.php, but my PHP isn't sufficient to actually modify it in a way that returns what I'm looking for...

    Any help would be much appreciated!

  2. uGoMobi
    Member
    Posted 3 years ago #

    Hi ncott,

    Here is the code which you can paste into the function.php file in your theme folder.

    function my_img_title_filter($attr) {
    	unset($attr['title']);
    	return $attr;
    	}
    add_filter( 'wp_get_attachment_image_attributes', 'my_img_title_filter' );
  3. ncott
    Member
    Posted 3 years ago #

    Perfect. Thanks very much!

Topic Closed

This topic has been closed to new replies.

About this Topic