Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1245232
    XcitingWeb
    Participant

    Hi!
    I want the featured images on a website of mine to be pulled from the thumbnail-sizes and not the full-sizes, because they are really small. Pulling from the thumbnail-sizes would speed up the websites because the loaded images are smaller.

    What do I have to add to the functions.php of the child of the X-Theme to make that happen?

    Thank you very much for your help!

    #1245596
    Rue Nel
    Moderator

    Hello There,

    Thanks for writing in! By default the featured image is displayed using the pre set image dimension in X. Sometimes it is displayed as in full size. To display the smaller dimension, please insert this following code in your child theme’s functions.php file.

    // Custom featured image displaying the smaller size image dimension in blog index
    // =============================================================================
    function x_featured_image( $cropped = '' ) {
    
      $stack     = x_get_stack();
      $fullwidth = ( in_array( 'x-full-width-active', get_body_class() ) ) ? true : false;
    
      if ( has_post_thumbnail() ) {
    
        if ( $cropped == 'cropped' ) {
          if ( $fullwidth ) {
            $thumb = get_the_post_thumbnail( NULL, 'entry-cropped-fullwidth', NULL );
          } else {
            $thumb = get_the_post_thumbnail( NULL, 'entry-cropped', NULL );
          }
        } else {
          if ( $fullwidth ) {
            $thumb = get_the_post_thumbnail( NULL, 'entry-fullwidth', NULL );
          } else {
            $thumb = get_the_post_thumbnail( NULL, 'entry', NULL );
          }
        }
    
        if ( is_home() || is_archive() ){
          $thumb = get_the_post_thumbnail( NULL, 'thumbnail', NULL );
        }
    
        switch ( is_singular() ) {
          case true:
            $get_description = get_post(get_post_thumbnail_id())->post_excerpt; 
            //var_dump($get_description);
            if(!empty($get_description)){
              //If description is not empty show the div echo '<div class="img-caption">' . $get_description . '</div>'; 
            }
    
            printf( '<div class="entry-thumb">%s</div>', $thumb );
            break;
          case false:
            printf( '<a href="%1$s" class="entry-thumb" title="%2$s">%3$s</a>',
              esc_url( get_permalink() ),
              esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ),
              $thumb
            );
            break;
        }
    
      }
    
    }
    // =============================================================================

    And if the thumbnail size is too little, you can change it to medium or large. Just find and replace it in this lines:

    if ( is_home() || is_archive() ){
          $thumb = get_the_post_thumbnail( NULL, 'thumbnail', NULL );
        }

    Hope this helps.

    #1246643
    XcitingWeb
    Participant

    Hi!
    Thank you very much. This worked perfectly! I attached my functions.php for future use. Solved!

    #1246676
    Rue Nel
    Moderator

    You’re welcome! We’re happy to help you out.
    If you need anything else we can help you with, don’t hesitate to open another thread.

  • <script> jQuery(function($){ $("#no-reply-1245232 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>