問題描述
我一直在閱讀,並試圖找出如何做到這一點,但由於某種原因,我似乎無法在我的孩子主題中覆蓋父函式。
我使用 TwentyTen 作為父母 – 任何人都可以告訴我為什麼我的小孩主題中的這個功能不會覆蓋父功能嗎?
// Override read more link
function osu_twentyten_continue_reading_link() {
return ' <a href="'.%20get_permalink()%20.%20'">' . __( 'Read on <span class="meta-nav">→</span>', 'twentyten-child' ) . '</a>';
}
function osu_twentyten_auto_excerpt_more( $more ) {
return ' …' . osu_twentyten_continue_reading_link();
}
remove_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
add_filter( 'excerpt_more', 'osu_twentyten_auto_excerpt_more' );
我以為你必須在 re-adding 之前刪除過濾器/動作等嗎?
謝謝,
OSU
最佳解決方案
您應該在主題設定後執行程式碼。
function osu_twentyten_continue_reading_link() {
return ' <a href="'.%20get_permalink()%20.%20'">' . __( 'Read on <span class="meta-nav">→</span>', 'twentyten-child' ) . '</a>';
}
function osu_twentyten_auto_excerpt_more( $more ) {
return ' …' . 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' );
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。