0
votes

I've stucked while trying to edit my current theme (called Carrie). I'm using a child theme. So what I'm trying to achieve is to edit/ehnance one of the theme's functions called 'carrie_header_post_show'. This function is in the parent file (located in inc directory) called theme-functions.php. The code looks as following:

function carrie_header_post_show() {
    $carrie_theme_options = carrie_get_theme_options();

    $header_post_html = '';

    if(isset($carrie_theme_options['header_post_id']) && $carrie_theme_options['header_post_id']<>'') {

      $header_post_id = $carrie_theme_options['header_post_id'];

      $header_post = get_post($header_post_id);

      if($header_post) {
        if(has_post_thumbnail( $header_post_id )) {

          $header_post_thumb_id = get_post_thumbnail_id($header_post_id);

          $header_post_image_url = wp_get_attachment_image_src( $header_post_thumb_id, 'carrie-blog-thumb-widget');

          $header_post_image = '<a href="'.get_permalink($header_post_id).'"><img src="'.esc_url($header_post_image_url[0]).'" alt="'.esc_attr($header_post->post_title).'"/></a>';

        } else {

          $header_post_image = '';

        }

        $header_post_categories_list = get_the_category_list(', ', 0, $header_post_id);

        $header_post_html .= '<div class="header-post-image hover-effect-img">'.wp_kses_post($header_post_image).'</div>';
        $header_post_html .= '<div class="header-post-details">';
        $header_post_html .= '<div class="header-post-category">';

        $title = wp_kses_post($header_post_categories_list);

        $header_post_html .= '</div>';
        $header_post_html .= '<div class="header-post-title"><a href="'.get_permalink($header_post_id).'">'.wp_kses_post($header_post->post_title).'</a></div>';
        $header_post_html .= '</div>';

        echo '<div class="header-post-content clearfix">'.wp_kses_post($header_post_html).'</div>';
      }

    }

}

What I would like to achieve is to add few lines of code. I've tried following actions:

  1. Creating inc folder in child theme, the destination file (theme-functions.php) as well and edit it. Doesn't work, got an error.
  2. Placing edited function into child's functions.php. Same here - doesn't work.
  3. Putting the function in the IF statement - same, doesn't work.

So what should i do then?

1
You can't define the same function twice. Why you can't change its definition directly in the current location? Why you can't remove it from current location and (re)define it where you need and how you need? You can alse check runkit_function_redefine().pavel
I don't want to edit directly files of the parent theme beacuse after update to newer version, i will loose everything. I've tried to unhook somehow the file but without success..Paweł Skaba

1 Answers

0
votes

What you should do is ask the theme author to make their function conditional using function_exists(), which will then allow you to declare your own version in the child theme. Child themes are loaded first, and if the parent verion of the function is conditional (which it should be) then it will never get executed if there's a version in your child theme.