Osu*_*Osu 4 wordpress function
我似乎无法让我的函数用于更改excerpt_moreTwenty Eleven父主题的过滤器.
我怀疑它可能实际上是add_action( 'after_setup_theme', 'twentyeleven_setup' );问题,但我甚remove_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_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">→</span>', 'clientname' ) . '</a>';
}
function clientname_auto_excerpt_more( $more ) {
return ' …' . clientname_continue_reading_link();
}
add_filter( 'excerpt_more', 'clientname_auto_excerpt_more' );
Run Code Online (Sandbox Code Playgroud)
谢谢,
奥苏
好吧,经过多次挫折之后,我找到了解决方案(我认为儿童主题意味着加快速度!?).我相信这是有效的,因为在设置父主题后运行'after_theme_setup'意味着你可以删除/覆盖Twenty Eleven的功能.
如果我理解正确,根据这个文档,首先运行子主题,然后运行父主题,然后运行Child Theme的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
这就是我的Child 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
Run Code Online (Sandbox Code Playgroud)
小智 5
您自己的答案是使事情复杂化,实际上不是必须的。我无法解释答案的原因,因为我在另一个答案中找到了它。但是无论如何,您总是可以从子主题中的父主题覆盖函数,尽管有时确实确实需要remove_filter()事先使用OR,例如,在这种情况下,您要做的就是增加添加的过滤器的优先级。案件:
add_filter( 'excerpt_more', 'clientname_auto_excerpt_more', 11 );
Run Code Online (Sandbox Code Playgroud)
这应该够了吧。如果不是,请增加数量。由于这个答案: