Support » Theme: Twenty Twelve » featured images generation elimination

  • Resolved Neil Wilson

    (@neil-wilson)


    Uploaded images get a featured image generated which I don’t use. The featured image is generated because of code in the function.php as follows:

    // This theme uses a custom image size for featured images, displayed on “standard” posts.
    add_theme_support( ‘post-thumbnails’ );
    set_post_thumbnail_size( 624, 9999 ); // Unlimited height, soft crop

    I tried adding code to my child function.php. which is (it does not work):

    <?php
    add_action(‘init’, ‘remove_624_image’);

    function remove_624_image() {
    remove_624_image(‘post-thumbnails’);
    }

    I added this at the bottom just above the “?>” line.

    Can anyone help?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Neil Wilson

    (@neil-wilson)

    FYI – My site is aafords.com – WordPress 5.3.2 Twenty Twelve Child theme; PHP 7.0.15

    Jarret

    (@jarretc)

    Hi, see the example code here regarding the remove_theme_support function

    https://developer.wordpress.org/reference/functions/remove_theme_support/#comment-1050

    Should work for what you’re wanting to do.

    Neil Wilson

    (@neil-wilson)

    Jarret,
    I added the code found at the link you provided just before the “?>” line at the end of my child function.php.

    To test, I uploaded an image. A featured image (624px wide) still got generated. My goal is to stop the 624px wide image from getting generated.

    I am guessing from the comments with code from the link you provided that it is stopping a featured image function within posts and pages. I don’t use this.

    My goal is to stop the extra, 624px wide image from getting generated.

    Can you or anyone help?

    Jarret

    (@jarretc)

    Ah, try this instead in your function

    set_post_thumbnail_size( 0, 0 );

    Neil Wilson

    (@neil-wilson)

    Jarret,
    My knowledge of PHP is zip. I created the following for inserting into my child function.php:

    // in Child Theme’s functions.php
    add_action( ‘after_setup_theme’, ‘stop_featured_image_creation’, 11 );

    function stop_featured_image_creation() {
    set_post_thumbnail_size( 0, 0 );
    }
    // insert before “?>” line

    I tested by uploading an image. The 624px image did not get generated. So, your information worked – Thank you muchly.

    Please verify the code I inserted is good PHP? And, please explain the “11”. My thinking is that the parent theme function.php loads (fires) with a priority of “10”. The “11” results in this particular code loading as priority “11” and therefore overrides the original code. Basically, the same as a child CSS file is used after the theme’s CSS file.

    I am trying to better understand.

    Thanks again,
    Neil Wilson

    Jarret

    (@jarretc)

    Hi, yes your code looks good. You’re on the right track about the priority number, but it isn’t based upon the parent theme’s functions.php file itself but whatever priority the code inside of that file uses.

    So you could have multiple different pieces of code inside of any theme’s functions.php file and each of those could run off of a different priority.

    Neil Wilson

    (@neil-wilson)

    Hello Jarret,
    I searched the twentytwelve functions.php file and found seven add_action entries (see below). None have a priority parameter (I think).

    So, this would mean that they each have a default priority of 10?

    Are priorities only set in add_action entries?

    add_action( ‘after_setup_theme’, ‘twentytwelve_setup’ );
    add_action( ‘wp_enqueue_scripts’, ‘twentytwelve_scripts_styles’ );
    add_action( ‘enqueue_block_editor_assets’, ‘twentytwelve_block_editor_styles’ );
    add_action( ‘widgets_init’, ‘twentytwelve_widgets_init’ );
    add_action( ‘template_redirect’, ‘twentytwelve_content_width’ );
    add_action( ‘customize_register’, ‘twentytwelve_customize_register’ );
    add_action( ‘customize_preview_init’, ‘twentytwelve_customize_preview_js’ );

    Jarret

    (@jarretc)

    For the most part I think WordPress defaults to a priority of 10. Priorities are set in a few different function, add_filter is another that comes to mind

    Hello Jarret,
    Okay, thanks for the information. I did find additional functions and some had priority set.

    I appreciate your help and information.

    Regards,
    Neil

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.