wordpress - 为什么我不能通过我的子主题功能覆盖 WP 的 'excerpt_more' 过滤器?

标签 wordpress function

我似乎无法让我的函数用于更改 21 个父主题的 excerpt_more 过滤器。

我怀疑它实际上可能是 add_action( 'after_setup_theme', 'twentyeleven_setup' ); 问题,但我什至尝试过 remove_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' ) 来摆脱 21 的功能,但我的功能仍然没有改变任何东西......

你能帮我吗?

这是functions.php 的完整代码:

http://pastie.org/3758708

这是我添加到/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' );

谢谢,

大须

最佳答案

好吧,在经历了很多挫折之后,我找到了解决方案(我认为 child 主题旨在加快速度!?)。我相信这是有效的,因为一旦设置了父主题,'after_theme_setup' 就会运行,这意味着您可以在那时删除/覆盖 21 的功能。

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

http://codex.wordpress.org/Child_Themes#Using_functions.php



http://codex.wordpress.org/Plugin_API/Action_Reference/after_setup_theme

这是我的子主题的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

关于wordpress - 为什么我不能通过我的子主题功能覆盖 WP 的 'excerpt_more' 过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10081129/

相关文章:

php - 对 woocommerce 中的价格进行四舍五入

php - 将 codeigniter 站点集成为 wordpress 插件

C中按下按键后连续调用函数

javascript - 简单的 JavaScript : "Reference Error: ' click' is undefined"

php - Woocommerce 设置类别最小购物车

php - 如何在没有 wp 的情况下从 mysql 数据库恢复 WordPress 博客 - 内容

c - 如何在 c 中返回 char (*)[6]?

python - 汉诺塔调用追踪

mysql - 无法登录本地主机 WordPress

python - 相对于行进的风向