[Support request] Featured image in the Header Element

Home Forums Support [Support request] Featured image in the Header Element

Home Forums Support Featured image in the Header Element

  • This topic has 23 replies, 4 voices, and was last updated 3 years ago by Tom.
Viewing 9 posts - 16 through 24 (of 24 total)
  • Author
    Posts
  • #1742440
    Elvin
    Staff
    Customer Support

    A part of this code is broken.

    add_action( 'init', function() {
      add_image_size( 'hero-image', 500, 300, true );
      add_image_size( 'eventhero-image', 700, 400, );
    } );

    In add_image_size( 'eventhero-image', 700, 400, ); the 400, has a , but you didn’t specify true or false for the cropping parameter.

    If you don’t want to specify, remove the ,. So you either do:
    add_image_size( 'eventhero-image', 700, 400 );
    OR
    add_image_size( 'eventhero-image', 700, 400, true );

    So it will look like this:

    add_action( 'init', function() {
      add_image_size( 'hero-image', 500, 300, true );
      add_image_size( 'eventhero-image', 700, 400, true );
    } );

    As for the PHP snippet for hero thumbnail:

    this should work:

    add_filter( 'generate_hero_thumbnail_id_size', function($size) {
      // Set defaults size if conditions not met
      $size = 'full';
      // Check if post is your_first_post_type
      if ( is_singular( 'events' ) ) {
        $size = 'eventhero-image';
      }
      // Else check if is your_other_post_type
      elseif ( is_singular( 'profiles' ) ) {
        $size = 'hero-image';
      }
      // Return the thumbnail size
      return $size;
    });

    I only added the CPT slugs and the image handle names.

    #1742593
    qpaq

    Ah I see, I corrected the size code. But problem persists; the resized thumbnails are not displayed on posts. This snippet causes the post to display the original uploaded sizes of the images.

    // Add new image sizes 
    add_action( 'init', function() {
      add_image_size( 'hero-image', 500, 300, true );
      add_image_size( 'eventhero-image', 700, 400 );
    } );
    
    add_filter( 'generate_hero_thumbnail_id_size', function($size) {
      // Set defaults size if conditions not met
      $size = 'full';
      // Check if post is your_first_post_type
      if ( is_singular( 'events' ) ) {
        $size = 'eventhero-image';
      }
      // Else check if is your_other_post_type
      elseif ( is_singular( 'profiles' ) ) {
        $size = 'hero-image';
      }
      // Return the thumbnail size
      return $size;
    });
    #1742636
    Elvin
    Staff
    Customer Support

    Ah I see, I corrected the size code. But problem persists; the resized thumbnails are not displayed on posts. This snippet causes the post to display the original uploaded sizes of the images.

    I believe this isn’t retroactive. If you’ve added the image size AFTER adding the image, you’ll have to make WordPress generate these added image sizes.

    Can you try regenerating the image sizes to be sure?
    https://wordpress.org/plugins/regenerate-thumbnails/

    #1743750
    qpaq

    Yes, I’ve regenerated the thumbnails with that plugin. I have both hero-image: 500×300 pixels (cropped to fit) and eventhero-image: 700×400 pixels (proportionally resized to fit inside dimensions) for each image. Yet the neither the events nor the profiles CPTs retrieve them.

    #1743885
    Elvin
    Staff
    Customer Support

    That’s quite strange.

    Can you link us to a sample post with images for events and profiles CPT?

    Can you let us temporarily access the backend as well to check the Header Element? So we could do a closer inspection.

    You can use the private information text field for the details. Let us know.

    #1744089
    qpaq

    Sure, I’ll write it down. Let me know what you’ve changed so I can record it.

    #1745326
    Elvin
    Staff
    Customer Support

    Ah I think I see the problem here.

    the code was written for a custom post type. Your posts don’t seem to be custom post types but rather, custom taxonomy terms under “Content type”.

    You may have to use is_tax() rather than is_singular(). Do you know the slug of “Content Type”? Let us know.

    #1745528
    qpaq

    Hi Elvin,

    Sorry my mistake. Not familiar so much with the terminology.

    The Content Type taxonomy is created by PODS. content_type is the slug I think you’re asking for.
    The two Content Types I would like to differentiate by the size of featured images are events and profiles

    I changed to snippet as you suggested, re-generated the thumbnails and purged the cache but the result is the same, problem not resolved.

    // Add new image sizes 
    add_action( 'init', function() {
      add_image_size( 'hero-image', 500, 300, true );
      add_image_size( 'eventhero-image', 700, 400 );
    } );
    
    add_filter( 'generate_hero_thumbnail_id_size', function($size) {
      // Set defaults size if conditions not met
      $size = 'full';
      // Check if post is your_first_post_type
      if ( is_tax ( 'events' ) ) {
        $size = 'eventhero-image';
      }
      // Else check if is your_other_post_type
      elseif ( is_tax ( 'profiles' ) ) {
        $size = 'hero-image';
      }
      // Return the thumbnail size
      return $size;
    });
    #1746254
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    You may need to ask Pods what condition you need to use. Looking at the body classes of that post, is_tax() won’t work, either. There doesn’t seem to be any other clues in the HTML as to which condition to use, unfortunately.

Viewing 9 posts - 16 through 24 (of 24 total)
  • You must be logged in to reply to this topic.