2nd featured image for mobile

Hi there!

I know that the theme post-thumbnail support is already declared in the theme but I need to add another image for posts to show that for mobiles. How can I add enable another image for mobiles?

Any filter or hook that I can use to add that meta box?

TA

Hi @abdurrehman,

Not filter or hook but by editing the function that handles the feature image. Please look for featured.php on this folder path:
\wp-content\themes\pro\framework\functions\frontend
\wp-content\themes\x\framework\functions\frontend

Look at this function:

  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 );
        }
      }

      switch ( is_singular() ) {
        case true:
          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;
      }

    }

  }

Copy that function on your child theme’s functions.php. Edit it as needed to add another instance of featured image for mobile view.

Unfortunately, actual code or adding it is outside the scope of our support. Thank you for understanding.

Okay, got it. Thanks for your input. :thumbsup:

Glad we could help.

Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.