尝试修改父主题中的“阅读更多”链接

我的父母有一个自定义的“阅读更多”功能。我想更改文本并添加到我的子主题 function.php 中。


这是父函数


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


噜噜哒
浏览 108回答 3
3回答

皈依舞

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

慕桂英3389331

我将父函数(if 语句中的所有内容)复制到我的子functions.php 文件中。然后简单地更改文本字符串。这有效。function newslite_implement_read_more( $more ) {&nbsp; &nbsp; $flag_apply_excerpt_read_more = apply_filters( 'newslite_filter_excerpt_read_more', true );&nbsp; &nbsp; if ( true !== $flag_apply_excerpt_read_more ) {&nbsp; &nbsp; &nbsp; &nbsp; return $more;&nbsp; &nbsp; }&nbsp; &nbsp; $output = $more;&nbsp; &nbsp; $read_more_text = __('More','newslite');&nbsp; &nbsp; if ( ! empty( $read_more_text ) ) {&nbsp; &nbsp; &nbsp; &nbsp; $output = ' <div class="read-more-text"><a href="' . esc_url( get_permalink() ) . '" class="read-more">' . esc_html( $read_more_text ) . '</a></div>';&nbsp; &nbsp; &nbsp; &nbsp; $output = apply_filters( 'newslite_filter_read_more_link' , $output );&nbsp; &nbsp; }&nbsp; &nbsp; return $output;}

呼唤远方

我只想删除它们的功能,并创建您自己的自定义功能。add_action( 'excerpt_more', 'custom_newslite_implement_read_more', 9999 );function custom_newslite_implement_read_more( $more ) {&nbsp; &nbsp; remove_filter( 'excerpt_length', 'newslite_excerpt_length', 999 );&nbsp; &nbsp; $flag_apply_excerpt_read_more = apply_filters( 'custom_newslite_filter_excerpt_read_more', true );&nbsp; &nbsp; if ( true !== $flag_apply_excerpt_read_more ) {&nbsp; &nbsp; &nbsp; &nbsp; return $more;&nbsp; &nbsp; }&nbsp; &nbsp; $output = $more;&nbsp; &nbsp; $read_more_text = __('read more','newslite'); // change read more to whatever you want&nbsp; &nbsp; if ( ! empty( $read_more_text ) ) {&nbsp; &nbsp; &nbsp; &nbsp; $output = ' <div class="read-more-text"><a href="' . esc_url( get_permalink() ) . '" class="read-more">' . esc_html( $read_more_text ) . '</a></div>';&nbsp; &nbsp; &nbsp; &nbsp; $output = apply_filters( 'custom_newslite_filter_read_more_link' , $output );&nbsp; &nbsp; }&nbsp; &nbsp; return $output;}
打开App,查看更多内容
随时随地看视频慕课网APP