Wordpress 为什么可以';ti覆盖WP';s';摘录"更多"&"x27;通过我的孩子主题函数过滤?

Wordpress 为什么可以';ti覆盖WP';s';摘录"更多"&"x27;通过我的孩子主题函数过滤?,wordpress,function,Wordpress,Function,我似乎无法让我的函数用于更改Twenty-Eleven父主题的摘录\u more过滤器 我怀疑它实际上可能是add_action('after_setup_theme','twentyeven_setup')这就是问题所在,但我甚至尝试了删除过滤器('extract\u more'、'twenteleven\u auto\u extract\u more')来删除Twenty Eleven的函数,但我的函数仍然没有改变任何东西 你能帮忙吗 下面是functions.php的完整代码: 以下是我

我似乎无法让我的函数用于更改Twenty-Eleven父主题的
摘录\u more
过滤器

我怀疑它实际上可能是
add_action('after_setup_theme','twentyeven_setup')这就是问题所在,但我甚至尝试了
删除过滤器('extract\u more'、'twenteleven\u auto\u extract\u more')
来删除Twenty Eleven的函数,但我的函数仍然没有改变任何东西

你能帮忙吗

下面是functions.php的完整代码:

以下是我添加到/mychildtheme/functions.php的函数

function clientname_continue_reading_link() {
    return ' <a href="'. esc_url( get_permalink() ) . '">' . __( 'Read more... <span class="meta-nav">&rarr;</span>', 'clientname' ) . '</a>';
}
function clientname_auto_excerpt_more( $more ) {
    return ' &hellip;' . clientname_continue_reading_link();
}
add_filter( 'excerpt_more', 'clientname_auto_excerpt_more' );
函数clientname\u continue\u reading\u link(){
返回“”;
}
函数clientname_auto_摘录_more($more){
返回“&hellip;”。clientname_continue_reading_link();
}
添加过滤器('extract\u more'、'clientname\u auto\u extract\u more');
谢谢


Osu

好吧,在经历了很多挫折之后,我找到了解决这个问题的办法(我认为儿童主题是为了加快速度!?)。我相信这是可行的,因为一旦父主题设置完毕,就会运行“after_theme_setup”,这意味着您可以删除/覆盖Twenty Eleven的功能

如果我理解正确,根据本文档,首先运行子主题,然后运行父主题,然后运行子主题的functions.php文件中的'after_Theme_setup'代码位:

这是my Child主题的functions.php文件中的内容,希望这对其他人有所帮助:

// ------------------------------------------------------------------
//                      // !AFTER_SETUP_THEME
// ------------------------------------------------------------------

/* Set up actions */
add_action( 'after_setup_theme', 'osu_setup' );

if ( ! function_exists( 'osu_setup' ) ):

function osu_setup() {

    // OVERRIDE : SIDEBAR GENERATION FUNCTION - NO WIDGETS FOR THIS SITE
    remove_action( 'widgets_init', 'twentyeleven_widgets_init' ); /* Deregister sidebar in parent */

    // OVERRIDE : EXCERPT READ MORE LINK FUNCTION
    function osu_readon_link() {
        return '...<a href="'. get_permalink() . '" class="readmore">' . __( 'Read More...', 'clientname' ) . '</a>';
    }
    // Function to override
    function osu_clientname_custom_excerpt_more( $output ) {
        if ( has_excerpt() && ! is_attachment() ) {
            // $output = trim($output);
            $output .= osu_readon_link();
        }
        return $output;
    }
    remove_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );
    add_filter( 'get_the_excerpt', 'osu_clientname_custom_excerpt_more' );
    remove_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' );
    add_filter( 'excerpt_more', 'osu_readon_link' );

    // OVERRIDE : EXCERPT LENGTH FUNCTION
    function osu_clientname_excerpt_length( $length ) {
        return 30;
    }
    remove_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );
    add_filter( 'excerpt_length', 'osu_clientname_excerpt_length' );

}
endif; // osu_setup
//------------------------------------------------------------------
//                      // !在设置主题之后
// ------------------------------------------------------------------
/*制定行动*/
添加动作(“设置主题后”、“osu设置”);
如果(!function_存在('osu_setup')):
功能osu_设置(){
//覆盖:边栏生成功能-此站点没有小部件
删除_操作('widgets_init','twentyeleven_widgets_init');/*在父级中取消注册侧栏*/
//覆盖:摘录读取更多链接功能
函数osu_readon_link(){
返回“…”;
}
//要覆盖的函数
函数osu_clientname_custom_摘录_more($output){
if(has_extract()&&!is_attachment()){
//$output=trim($output);
$output.=osu_readon_link();
}
返回$output;
}
删除过滤器(“获取摘录”、“twentyeleven自定义摘录”或“更多”);
添加过滤器(“获取摘录”、“osu客户名称”自定义摘录“更多”);
移除过滤器(“摘录更多”、“twentyeleven自动摘录更多”);
添加过滤器(“摘录更多”、“osu阅读链接”);
//覆盖:摘录长度函数
函数osu_客户端名称_摘录_长度($length){
返回30;
}
移除过滤器(“摘录长度”、“twentyeleven摘录长度”);
添加过滤器('extract_length'、'osu_clientname_extract_length');
}
endif;//osu_设置

你自己的答案让事情变得复杂,真的不必要。我无法解释我的答案的原因,因为我在另一个答案中找到了它。但在任何情况下,您都可以在子主题中覆盖父主题中的函数,尽管有时您确实需要事先使用
删除\u filter()
,或者像在本例中一样,您所要做的就是增加所添加过滤器的优先级,在您的情况下:

add_filter( 'excerpt_more', 'clientname_auto_excerpt_more', 11 );
这应该能奏效。如果没有,增加数字。
感谢:

试试吧谢谢你的建议,但我也遇到了同样的问题。找到答案-您需要将删除过滤器和添加过滤器添加到“after_setup_theme”调用中。我想我一定是疯了!非常感谢。