我一直在阅读并尝试找出解决方法,但是由于某些原因,我似乎无法在子主题中覆盖父函数。

我将TwentyTen用作父对象-谁能告诉我为什么子主题中的此功能没有覆盖父功能?

// Override read more link
function osu_twentyten_continue_reading_link() {
 return ' <a href="'. get_permalink() . '">' . __( 'Read on <span class="meta-nav">&rarr;</span>', 'twentyten-child' ) . '</a>';
}
function osu_twentyten_auto_excerpt_more( $more ) {
 return ' &hellip;' . osu_twentyten_continue_reading_link();
}
remove_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
add_filter( 'excerpt_more', 'osu_twentyten_auto_excerpt_more' );


我认为您必须删除过滤器/操作等。在重新添加之前正确吗?

,谢谢,

osu

#1 楼

您应该在主题设置后运行代码。

function osu_twentyten_continue_reading_link() {
    return ' <a href="'. get_permalink() . '">' . __( 'Read on <span class="meta-nav">&rarr;</span>', 'twentyten-child' ) . '</a>';
}

function osu_twentyten_auto_excerpt_more( $more ) {
    return ' &hellip;' . osu_twentyten_continue_reading_link();
}

function my_child_theme_setup() {
    remove_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
    add_filter( 'excerpt_more', 'osu_twentyten_auto_excerpt_more' );
}

add_action( 'after_setup_theme', 'my_child_theme_setup' );


评论


是的而且它不能直接起作用的原因是,子主题的代码先于父主题的代码加载。

–稀有
2011年1月23日14:37