WordPress.org

Ready to get started?Download WordPress

Forums

Since WordPress 3.5 cannot change img attributes (4 posts)

  1. blogodisea
    Member
    Posted 2 years ago #

    Sorry about my bad english.

    I wanted that every time i upload a image, wordpress automatically make this code when i insert the image:
    <img src="URLOFTHEIMAGE" width="WIDTHOFTHEIMAGE" height="HEIGHTOFTHEIMAGE" title="NAMEOFTHEIMAGE" alt="NAMEOFTHEIMAGE">

    I wanted to delete the class feature that WordPress inserts in every image and to add the title and alt codes with the names of the image i uploaded.

    I used this code that was functioning since the new versiĆ³n of WordPress 3.5, but now it's not working anymore.

    function image_tag($html, $id, $alt, $title) {
    return preg_replace(array(
    '/alt=""/i'
    ),
    array(
    'alt="' . $title . '"'
    ),
    $html);
    }
    add_filter('get_image_tag', 'image_tag', 0, 4);
    
    function image_tag_class($class, $id, $align, $size) {
    return ;
    }
    add_filter('get_image_tag_class', 'image_tag_class', 0, 4);

    Can anyone tell me how can i make it work again? Thanks.

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    Have you tried:

    - deactivating all plugins to see if this resolves the problem. If this works, re-activate the plugins one by one until you find the problematic plugin(s).

    - switching to the Twenty Eleven theme to rule out any theme-specific problems.

    - resetting the plugins folder by FTP or PhpMyAdmin. Sometimes, an apparently inactive plugin can still cause problems.

  3. blogodisea
    Member
    Posted 2 years ago #

    What? It's nothing about the plugins, WordPress is OK. I'm telling about something to hack the way that WordPress insert the html of the images.

    Normally it makes something like this
    <img src="URLOFTHEIMAGE" width="WIDTHOFTHEIMAGE" height="HEIGHTOFTHEIMAGE" Class="CLASS" alt="NAMEOFTHEIMAGE">

    and i want to make this one

    <img src="URLOFTHEIMAGE" width="WIDTHOFTHEIMAGE" height="HEIGHTOFTHEIMAGE" title="NAMEOFTHEIMAGE" alt="NAMEOFTHEIMAGE">

    The hack code i was using in functions.php worked fine, but now it's not working since the new 3.5 version.

  4. shaunklink
    Member
    Posted 2 years ago #

    I think I kind of understand what you are saying... and if so, I am having the same problem.

    I had the following code in my functions.php file to remove image attributes on upload:

    add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 );
    	add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );
    	// Genesis framework only
    	add_filter( 'genesis_get_image', 'remove_thumbnail_dimensions', 10 );
    	// Removes attached image sizes as well
    	add_filter( 'the_content', 'remove_thumbnail_dimensions', 10 );
    	function remove_thumbnail_dimensions( $html ) {
    	    $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
    	    return $html;
    	}

    since the upgrade to 3.5, it no longer works. There are no errors or anything but it just dosn't seem to do what its supposed to.

Topic Closed

This topic has been closed to new replies.

About this Topic