2017-02-13 108 views
0

我有一个与Remove_filter()的问题。删除过滤器的作品,但不是100%,它不会删除第一个3点从阅读更多,它不会取代父节选。Wordpress删除阅读更多摘录

更明确地说什么,我试图做的是去除更多并将其转换为[...]

我想这是从儿童主题完成。

以下是截图示例BeforeAfter

父主题的functions.php代码

function new_excerpt_more($more) { 
    global $post; 
    return '… <a href="'. get_permalink($post->ID) . '">' . 'Read More! &raquo;'  . '</a>'; 
    } 
    add_filter('excerpt_more', 'new_excerpt_more'); 

儿童主题的functions.php代码。

 function child_theme_setup() { 
     // override parent theme's 'more' text for excerpts 
     remove_filter('excerpt_more', 'new_excerpt_more'); 

     } 
    add_action('after_setup_theme', 'child_theme_setup'); 
    // Replaces the excerpt "Read More" text by a link 
    function new_excerpt($more) { 
    global $post; 
    return '<a class="moretag" href="'. get_permalink($post->ID) . '">[...]      </a>'; 
     } 
     add_filter('excerpt', 'new_excerpt'); 
+0

明确指出你的问题。 –

+0

@HappyCoding,我编辑它 –

回答

2

你只需要稍微更新一下你的代码。

// Changing excerpt more 
function new_excerpt_more($more) { 
    global $post; 
    remove_filter('excerpt_more', 'new_excerpt_more'); 
    return ' <a class="read_more" href="'. get_permalink($post->ID) . '">' . ' do whatever you want to update' . '</a>'; 
} 
add_filter('excerpt_more','new_excerpt_more',11); 

一个钩子的缺省优先级是10.这可能是父主题的钩其次得到补充,这意味着这两个钩子和家长钩具有相同的优先级,但父母的来了所以最后它不反映变化。

+0

它仍然是一样的,3个点仍然存在。我写在那里它不会改变。 –

+0

更新钩优先级为11 ..然后检查结果 –

+0

工作,非常感谢你! :)。 –