WordPress.org

Ready to get started?Download WordPress

Forums

Change IMG Class WordPress Outputs (6 posts)

  1. christopherburton
    Member
    Posted 1 year ago #

    Is it possible to change the classes WordPress outputs for Img tags?

    I am trying to change .size-full to .full but I couldn't find anything in the includes files.

  2. David Choi
    Member
    Posted 1 year ago #

  3. christopherburton
    Member
    Posted 1 year ago #

    @WpThemes777.com Thanks but I found the solution in media.php inside the includes folder.

    Changed this:
    $class = 'align' . esc_attr($align) .' size-' . esc_attr($size) . ' wp-image-' . $id;

    to this:
    $class = 'align' . esc_attr($align) . ' ' . esc_attr($size) . ' wp-image-' . $id;

  4. David Choi
    Member
    Posted 1 year ago #

    Yes, it's always possible to edit the source codes, but it's not recommended due to upgrades. Actually you should never touch the WordPress source files.

    A better approach in this case will be using jQuery javascript

    http://stackoverflow.com/questions/3452778/jquery-change-class-name

    loading the *.js file via wp_enqueue_script

    http://codex.wordpress.org/Function_Reference/wp_enqueue_script

    in your themes functions.php file, so you don't have to worry about upgrades.

  5. christopherburton
    Member
    Posted 1 year ago #

    Great point. I completely forgot about that. I was also thinking to use a filter to remove the align class and edit size-

  6. christopherburton
    Member
    Posted 1 year ago #

    I tried the following code but nothing changed. Not sure how to go about this.

    add_filter( 'post_thumbnail_html', 'remove_image_classes', 10 );
    add_filter( 'image_send_to_editor', 'remove_image_classes', 10 );
    
    function remove_image_classes( $html ) {
        $html = preg_replace( '/(size-|alignnone)/', "", $html );
        return $html;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic