• As I don’t need thumbnails for the images I upload, I disabled thumbnail generation by setting to zero all thumbnails sizes in the Media Settings page.

    I noticed that the resized image of the custom header is still generated for every image I upload through the Media Gallery page, the same as if it were uploaded as a header image through the Custom Header page in the Appearance menu.

    Is there a way I can disable this resizing?

    I couldn’t locate the code that does the actual resizing, I think it’s theme-specific as there are themes that do not support custom header images.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The featured thumbnail size is set in the functions.php, if you do not want your theme to support featured images then in functions php find:

    // This theme uses post thumbnails
    add_theme_support( 'post-thumbnails' );

    Remark Call:

    // This theme uses post thumbnails
    // REMARKED by alesss add_theme_support( 'post-thumbnails' );

    A few lines below find the lines that set the size:

    // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
    set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );

    Remark Call:

    // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
    // REMARKED alesss set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );

    Polite Suggestions:
    Be aware that if you edit the default twenty ten theme, and this is updated.
    If you allow WordPress to update the theme, your changes will be lost, to avoid this consider using a child theme to protect your changed files.

    Syntax errors in code can produce a fatal error locking you out of the admin area and editor.

    To limit this create a local environment and test changes befor deploying these to a production website.

    HTH

    David

    Thread Starter alesss

    (@alesss)

    Hi David,

    thanks for the help. I commented out just the set_post_thumbnail_size() function and images are not resized anymore.

    I’m actually building a child theme, and I was wondering if I could use remove_filter or remove_action to accomplish the same without modifying the original function.php.

    I’ve googled a bit, but I don’t understand how to find out:

    1. if the function set_post_thumbnail_size() is an action or a filter

    2. where to find the action_hook name or filter_hook name relative to set_post_thumbnail_size()

    aless

    I did query this before as I wanted to remove support for the custom background, backgrounds are not supported, so there was no way.

    The thumbnail support is not added with actions or filters, nor did the theme creators wrap them in a function with the if ( statement.

    However, there are two arguments you can pass to add_theme_support().

    <?php add_theme_support('post-thumbnails'); ?>

    There is also a function remove_theme_support(), not sure if it works in reverse, try adding nested inside you child themes after_setup_theme function.

    /* Remove theme support for Post Thumbnails */
    function remove_custom_theme_support(){
    	remove_theme_support('post-thumbnails');
    }
    add_action( 'after_setup_theme', 'remove_custom_theme_support', 11 );

    Other Information
    This part may help others wondering about the same issues.

    Remove Filter and Remove Action
    These can only be used in a child theme if add_filter or add_action was used in the parent.

    As an example the widgets are loaded with an add_action call, so if you wanted a child theme with no widgets, or you wanted your own widget names, inside ‘after_setup_theme’, you would remove twenty ten’s and create your own.

    Parents functions.php has these lines:

    /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
    add_action( 'widgets_init', 'twentyten_widgets_init' );

    In the child themes after_setut_theme function we might want to remove the twenty ten widget areas.

    /* Remove the Twenty Ten registered sidebars */
    remove_action( 'widgets_init', 'twentyten_widgets_init' );

    After which we might want to add back our own widget areas.

    /** Add our Widgetized Areas */
    function child_widgets_init() {
    
    // Load our Widget Area Names and ID's into an Array
    $widgets = array (
    	array(
    		"name" => "Sidebar One",
              "id" => "sidebar-1"),
    	array(
    		"name" => "Sidebar Two",
              "id" => "sidebar-2"),
    	);
    
    	/* Loop through the array and add our Widgetised areas */
    	foreach ($widgets as $widget) {
    		register_sidebar( array(
    			'name' => __( $widget['name'], 'twentyten' ),
    			'id' => $widget['id'],
    			'description' => __( $widget['name'] .' Area', 'twentyten' ),
    			'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    			'after_widget' => '</li>',
    			'before_title' => '<h3 class="widget-title">',
    			'after_title' => '</h3>',
    		) );
    	}
    }
    /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
    add_action( 'widgets_init', 'child_widgets_init' );

    Functions
    If in the parent theme the function starts with, if ( !

    Example could be you wanted to copy the comments code to the child and change it, in the parent it starts:

    if ( ! function_exists( 'twentyten_comment' ) ) :

    So you can copy this function across to the child and change it, this function with the same name would be placed after the after_setup_theme function and not inside.

    WordPress runs the childs functione.php first, so it would then load the function ‘twentyten_comments’ from the child theme.
    When it runs the parents functions.php it would see that the function is already loaded and skip it.

    You cannot have a function with the same name as the parent if it does not start with:

    if ( ! function_exists( 'function_name' ) ) :

    After the two functions.php files are loaded WordPress will then action the ‘after_setup_theme’ functions, adding and removing.

    There clear as mud?

    Check out my tutorial series on child themes and template parts!

    Download this sample theme for my second tutorial set, this has some of the example code I have used here in the functions.php

    HTH

    David

    Thread Starter alesss

    (@alesss)

    Thanks for the very detailed explanation David. As I want to mantain the posts thumbnail function and only remove the resizing part, I opted for commenting out the one line in the original functions.php: the theme is for my personal use, so I guess I can remember to comment it out again when I upgrade to newer versions of Twenty Ten 🙂

    As for the action/filter, I finally got it, thanks! And nice tutorials you have on your page.

    aless

    Thanks,
    I think you may be able to overide the call in the parent without the need to edit the parent.
    In the childs functions.php add this code, change the width and height to your prefered size.

    This seemed to work in another child theme I have.

    add_action( 'init', 'init_theme_setup' );
    
    function init_theme_setup() {
       // We'll be using custom post thumbnails.
       set_post_thumbnail_size( 120, 90, true );
    }

    I never checked what other image sizes it also created, but the get_thumbnail() featured image was 120px * 90px.

    HTH

    David

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to prevent resizing of custom header image (twenty ten)’ is closed to new replies.