WordPress.org

Forums

Creation of XXX*288 and XXX*300 images by Twenty Eleven theme (6 posts)

  1. gnucco2
    Member
    Posted 2 years ago #

    Hi to all, and sorry if this is already asked, but it's about one week that I'm looking for a solution to a problem and I can't find an answer.
    I run a photoblog. I installed WordPress 3.4 and I'm using Twenty Eleven default theme. I disabled the creation of thumbnails, medium and large images since I only want to show my pictures at their full size. But Twenty Eleven theme creates also two copies of my uploaded pictures, with a height of 288 and 300 pixels. I want to disable the creation of these images, since I always have to delete them manually.
    What pieces of code should I delete?
    Thanks a lot

    bye, Fede

  2. Digital Raindrops
    Member
    Posted 2 years ago #

    To answer the topic have a look at this plugin, read the information and test if possible.

    ---------------------------------------------------------------
    The additional image size is set in the themes functions.php

    // Used for large feature (header) images.
    add_image_size( 'large-feature', $custom_header_support['width'],$custom_header_support['height'], true );
    
    // Used for featured posts if a large-feature doesn't exist.
    add_image_size( 'small-feature', 500, 300 );

    Do not edit any of the default themes files, if you are doing any modifications use a child theme.

    Why is there is no core function to remove_image_size( 'small-feature' );

    UNTESTED CODE:
    So in a child themes functions.php

    /**
     * Unset unwanted image sizes in child theme
     */
    function dr_remove_image_size( $name ) {
    	global $_wp_additional_image_sizes;
    	unset( $_wp_additional_image_sizes[$name] );
    }
    
    function dr_unset_images(){
    	dr_remove_image_size( 'small-feature' );
    	/* Not using the header images */
    	dr_remove_image_size( 'large-feature' );
    }
    add_action( 'after_setup_theme', 'dr_unset_images' );

    I would just live with the images unless I had thousands of posts!

    HTH

    David

  3. gnucco2
    Member
    Posted 2 years ago #

    Thanks for your interest and help, Digital Raindrops.
    Me and my co-author post a lot of images so our web space finish very soon ;-)
    I've installed the plugin you suggested but I don't understand it. It doesn't allow me to select the first three intermediate fields:

    post-thumbnail 	1000px 	288px 	crop
    large-feature 	1000px 	288px 	crop
    small-feature 	500px 	300px

    saying that

    Additional uneditable sizes added by another plugin or theme via set_post_thumbnail_size() or add_image_size(). These sizes are ignored while creating or deleting sizes with this plugin.

    So I've tried to edit my functions.php copied in twentyeleven child directory, but if I put your code at the end of it wordpress generates an error saying this:

    Fatal error: Cannot redeclare twentyeleven_excerpt_length() (previously declared in /membri/chillesperienza/wordpress/wp-content/themes/twentyeleven-child/functions.php:335) in /membri/chillesperienza/wordpress/wp-content/themes/twentyeleven/functions.php on line 337

    Line 329-338 of functions.php is

    /**
     * Sets the post excerpt length to 40 words.
     *
     * To override this length in a child theme, remove the filter and add your own
     * function tied to the excerpt_length filter hook.
     */
    function twentyeleven_excerpt_length( $length ) {
    	return 40;
    }
    add_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );

    Did I do something wrong?
    Thanks again
    Fede

  4. Digital Raindrops
    Member
    Posted 2 years ago #

    I have just tested the code I posted and cannot get it to work, it will not recognise the global, so I am stumped!

    With the child themes functions.php you create it like the style.css and do not copy it across.

    Sample child themes functions.php

    <?php
    
    /** Tell WordPress to run post_theme_setup()
     *  when the 'after_setup_theme' hook is run.
     */
    
    add_action( 'after_setup_theme', 'post_theme_setup' );
    
    if ( !function_exists( 'post_theme_setup' ) ):
    function post_theme_setup() {
    
    }
    endif;

    HTH

    David

  5. gnucco2
    Member
    Posted 2 years ago #

    Well, in the end I just commented out the three functions in TwentyEleven functions.php

    /*	set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['height'], true ); */
    
    /*	add_image_size( 'large-feature', $custom_header_support['width'], $custom_header_support['height'], true ); */
    
    /*	add_image_size( 'small-feature', 500, 300 ); */

    and now I don't have any intermediate picture...

    Thanks for pointing me in this direction
    bye, Fede

  6. Digital Raindrops
    Member
    Posted 2 years ago #

    Hi,
    I have just had another look at the twenty eleven functions.php

    The good news is the function 'twentyeleven_setup' is pluggable, dumb thing is I wrote about it back in April.

    if ( ! function_exists( 'twentyeleven_setup' ) ):
    function twentyeleven_setup() {
    }
    endif;

    That means we can just copy the whole function from the parent to the child, we do not rename it, the childs function will run and the parents will not!

    Copy lines 47 - 210 from the parent
    From

    /**
     * Tell WordPress to run twentyeleven_setup() when the 'after_setup_theme' hook is run.
     */
    add_action( 'after_setup_theme', 'twentyeleven_setup' );

    Down to the endif;

    endif; // twentyeleven_setup

    That function is now ours to change whatever we want!

    That has opened up my thinking!

    Glad I answered this one!

    David

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.