How to override the theme global functions on child theme?

Hello there!

I want to override the X-theme “framework/functions/global/featured.php” file, to add captions under the single post featured image. I’ve made the similar structure in the child theme but it’s not affected.

How it’s possible to override the global php’s?

Thank you!

Hi there,

You will need to copy the function in question directly to the functions.php file of your Child Theme and then do your changes there. For example:

if ( ! function_exists( 'x_featured_image' ) ) :
  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;
      }

    }

  }
endif;

The function above is the featured image function that you can copy to the functions.php and do the changes there. Don’t look at the functions as files and as single functions that you can copy/paste to your child theme.

Thank you.

1 Like

Thank you @christopher.amirian :smiley:

It’s working perfectly!!!

Have a great day!
Regards,
ImOk team

You’re welcome.

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