Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
153 views
in Technique[技术] by (71.8m points)

php - Overiding parent theme functions with a Child theme in WordPress

I am trying to override the Parent theme function.php file with a function i have in my child themes function.php file but i'm getting a couple of errors. Here's what iv'e done so far..

function remove_et_postinfo_meta_actions() {

remove_action('after_setup_theme','et_postinfo_meta',3);
}

add_action('init', 'remove_et_postinfo_meta_actions');


add_action('after_setup_theme', 'cc_et_postinfo_meta', 3);


if ( ! function_exists( 'cc_et_postinfo_meta' ) ){
function cc_et_postinfo_meta( $postinfo, $date_format, $comment_zero, $comment_one, $comment_more          ){
    global $themename;

    $postinfo_meta = '';

    if ( in_array( 'author', $postinfo ) ){
        $postinfo_meta .= ' ' . esc_html__('by',$themename) . ' ' .     et_get_the_author_posts_link();
    }

    if ( in_array( 'date', $postinfo ) )
        $postinfo_meta .= ' ' . esc_html__('on',$themename) . ' ' . get_the_time( $date_format );

    if ( in_array( 'categories', $postinfo ) )
        $postinfo_meta .= ' ' . esc_html__('in',$themename) . ' ' . get_the_category_list(', ');

    if ( in_array( 'comments', $postinfo ) )
        $postinfo_meta .= ' ' . et_get_comments_popup_link( $comment_zero, $comment_one,   $comment_more );

    if ( '' != $postinfo_meta ) $postinfo_meta = __('Posted',$themename) . ' ' . $postinfo_meta;

    echo $postinfo_meta;
 }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What are the errors you are getting?

As described in the WordPress codex:

"Unlike style.css, the functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.)" (source: http://codex.wordpress.org/Child_Themes)

So, it is not possible to override the functions.php file, but you can add your own functions to the functions.php file in your child theme. Be sure to prefix your own function so it won't conflict with the functions in the parent theme.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...