尝试修改父主题中的"Read more"链接



我的父母他们有一个自定义的"阅读更多";作用我想更改文本并添加到我的子主题功能中。hp.

这是家长他们的功能

add_filter( 'excerpt_length', 'newslite_excerpt_length', 999 );
if ( ! function_exists( 'newslite_implement_read_more' ) ) :
function newslite_implement_read_more( $more ) {
$flag_apply_excerpt_read_more = apply_filters( 'newslite_filter_excerpt_read_more', true );
if ( true !== $flag_apply_excerpt_read_more ) {
return $more;
}
$output = $more;
$read_more_text = __('continue reading','newslite');
if ( ! empty( $read_more_text ) ) {
$output = ' <div class="read-more-text"><a href="' . esc_url( get_permalink() ) . '" class="read-more">' . esc_html( $read_more_text ) . '</a></div>';
$output = apply_filters( 'newslite_filter_read_more_link' , $output );
}
return $output;
}
endif;
add_action( 'excerpt_more', 'newslite_implement_read_more' );

我只需要删除它们的函数,然后创建自己的自定义函数。

add_action( 'excerpt_more', 'custom_newslite_implement_read_more', 9999 );
function custom_newslite_implement_read_more( $more ) {
remove_filter( 'excerpt_length', 'newslite_excerpt_length', 999 );
$flag_apply_excerpt_read_more = apply_filters( 'custom_newslite_filter_excerpt_read_more', true );
if ( true !== $flag_apply_excerpt_read_more ) {
return $more;
}
$output = $more;
$read_more_text = __('read more','newslite'); // change read more to whatever you want
if ( ! empty( $read_more_text ) ) {
$output = ' <div class="read-more-text"><a href="' . esc_url( get_permalink() ) . '" class="read-more">' . esc_html( $read_more_text ) . '</a></div>';
$output = apply_filters( 'custom_newslite_filter_read_more_link' , $output );
}
return $output;
}

尝试代码:

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');

我将父函数(if语句中的所有内容(复制到了我的子functions.php文件中。然后简单地更改了文本字符串。这起到了作用。

function newslite_implement_read_more( $more ) {
$flag_apply_excerpt_read_more = apply_filters( 'newslite_filter_excerpt_read_more', true );
if ( true !== $flag_apply_excerpt_read_more ) {
return $more;
}
$output = $more;
$read_more_text = __('More','newslite');
if ( ! empty( $read_more_text ) ) {
$output = ' <div class="read-more-text"><a href="' . esc_url( get_permalink() ) . '" class="read-more">' . esc_html( $read_more_text ) . '</a></div>';
$output = apply_filters( 'newslite_filter_read_more_link' , $output );
}
return $output;
}

最新更新