• Resolved Nextendweb

    (@nextendweb)


    Hi @joedolson,
    our plugin use data-title="" attributes, but the "Remove title attributes inserted into post content and featured images." option removes these titles. I checked your code and I think I have a solution for you.

    Adding [\s] to the start of the regexp will match a whitespace before the title attribute, so it will only match <img title="test"/>, but does not match <div data-title="test"></div>

    Original code:

    function wpa_image_titles( $content ) {
    	$results = array();
    	preg_match_all( '|title="[^"]*"|U', $content, $results );
    	var_dump($results);
    	foreach ( $results[0] as $img ) {
    		$content = str_replace( $img, '', $content );
    	}
    
    	return $content;
    }

    Updated code:

    function wpa_image_titles( $content ) {
    	$results = array();
    	preg_match_all( '|[\s]title="[^"]*"|U', $content, $results );
    	var_dump($results);
    	foreach ( $results[0] as $img ) {
    		$content = str_replace( $img, '', $content );
    	}
    
    	return $content;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Fix for Remove title attributes’ is closed to new replies.