允许在divi主题摘录中使用所有html标记和样式

允许在divi主题摘录中使用所有html标记和样式,html,wordpress,wordpress-theming,truncate,strip-tags,Html,Wordpress,Wordpress Theming,Truncate,Strip Tags,如何允许使用truncate post而不是普通摘录功能的divi主题摘录中的所有hmtl、短代码和样式设置。我试着注释掉一些行,但不起作用 if ( ! function_exists( 'truncate_post' ) ) { function truncate_post( $amount, $echo = true, $post = '', $strip_shortcodes = false ) { global $shortname; if ( empty( $po

如何允许使用truncate post而不是普通摘录功能的divi主题摘录中的所有hmtl、短代码和样式设置。我试着注释掉一些行,但不起作用

if ( ! function_exists( 'truncate_post' ) ) {

function truncate_post( $amount, $echo = true, $post = '', $strip_shortcodes = false ) {
    global $shortname;

    if ( empty( $post ) ) global $post;

    if ( post_password_required( $post ) ) {
        $post_excerpt = get_the_password_form();

        if ( $echo ) {
            echo et_core_intentionally_unescaped( $post_excerpt, 'html' );
            return;
        }

        return $post_excerpt;
    }

    $post_excerpt = apply_filters( 'the_excerpt', $post->post_excerpt );

    if ( 'on' === et_get_option( $shortname . '_use_excerpt' ) && ! empty( $post_excerpt ) ) {
        if ( $echo ) {
            echo et_core_intentionally_unescaped( $post_excerpt, 'html' );
        } else {
            return $post_excerpt;
        }
    } else {
        // get the post content
        $truncate = $post->post_content;

        // remove caption shortcode from the post content
        $truncate = preg_replace( '@\[caption[^\]]*?\].*?\[\/caption]@si', '', $truncate );

        // remove post nav shortcode from the post content
        $truncate = preg_replace( '@\[et_pb_post_nav[^\]]*?\].*?\[\/et_pb_post_nav]@si', '', $truncate );

        // Remove audio shortcode from post content to prevent unwanted audio file on the excerpt
        // due to unparsed audio shortcode
        $truncate = preg_replace( '@\[audio[^\]]*?\].*?\[\/audio]@si', '', $truncate );

        // Remove embed shortcode from post content
        $truncate = preg_replace( '@\[embed[^\]]*?\].*?\[\/embed]@si', '', $truncate );

        // Remove script and style tags from the post content
        $truncate = wp_strip_all_tags( $truncate );

        if ( $strip_shortcodes ) {
            $truncate = et_strip_shortcodes( $truncate );
            $truncate = et_builder_strip_dynamic_content( $truncate );
        } else {
            // Check if content should be overridden with a custom value.
            $custom = apply_filters( 'et_truncate_post_use_custom_content', false, $truncate, $post );
            // apply content filters
            $truncate = false === $custom ? apply_filters( 'the_content', $truncate ) : $custom;
        }

        /**
         * Filter automatically generated post excerpt before it gets truncated.
         *
         * @since 3.17.2
         *
         * @param string $excerpt
         * @param integer $post_id
         */
        $truncate = apply_filters( 'et_truncate_post', $truncate, $post->ID );

        // decide if we need to append dots at the end of the string
        if ( strlen( $truncate ) <= $amount ) {
            $echo_out = '';
        } else {
            $echo_out = '...';
            // $amount = $amount - 3;
        }

        // trim text to a certain number of characters, also remove spaces from the end of a string ( space counts as a character )
        $truncate = rtrim( et_wp_trim_words( $truncate, $amount, '' ) );

        // remove the last word to make sure we display all words correctly
        if ( ! empty( $echo_out ) ) {
            $new_words_array = (array) explode( ' ', $truncate );
            array_pop( $new_words_array );

            $truncate = implode( ' ', $new_words_array );

            // append dots to the end of the string
            $truncate .= $echo_out;
        }

        if ( $echo ) {
            echo et_core_intentionally_unescaped( $truncate, 'html' );
        } else {
            return $truncate;
        }
    };
}
如果(!function_存在('truncate_post')){
函数truncate\u post($amount,$echo=true,$post='',$strip\u shortcodes=false){
全球$shortname;
if(空($post))全局$post;
如果(需要密码($post)){
$post_extract=获取密码表单();
如果($echo){
echo et_core_故意_unscaped($post_摘录,'html');
返回;
}
返回$post_摘录;
}
$post\u extract=apply\u过滤器('the\u extract',$post->post\u extract);
如果('on'==et_get_option($shortname.'u use_extract')&&&!empty($post_extract)){
如果($echo){
echo et_core_故意_unscaped($post_摘录,'html');
}否则{
返回$post_摘录;
}
}否则{
//获取帖子内容
$truncate=$post->post\U内容;
//从帖子内容中删除标题短代码
$truncate=preg\u replace('@\[caption[^\]]*?\].\[\/caption]@si',''$truncate);
//从帖子内容中删除帖子导航快捷码
$truncate=preg\U replace(“@\[et\U pb\U post\U nav[^\]*?\].*?\[\/et\U pb\U post\U nav]@si',”$truncate);
//从文章内容中删除音频短代码,以防止摘录中出现不需要的音频文件
//由于未解析的音频短代码
$truncate=preg\u replace('@\[audio[^\]]*?\].\[\/audio]@si',''$truncate);
//从帖子内容中删除嵌入短代码
$truncate=preg\u replace('@\[embed[^\]]*?\].\[\/embed]@si',''$truncate);
//从帖子内容中删除脚本和样式标记
$truncate=wp\u strip\u all\u标记($truncate);
if($strip\u短代码){
$truncate=et_strip_短码($truncate);
$truncate=et\u builder\u strip\u动态内容($truncate);
}否则{
//检查是否应使用自定义值覆盖内容。
$custom=apply_filters('et_truncate_post_use_custom_content',false,$truncate,$post);
//应用内容过滤器
$truncate=false===$custom?应用_过滤器('the_content',$truncate):$custom;
}
/**
*筛选自动生成的帖子摘录,然后将其截断。
*
*@自3.17.2起
*
*@param string$摘录
*@param integer$post_id
*/
$truncate=apply_过滤器('et_truncate_post',$truncate,$post->ID);
//决定是否需要在字符串末尾添加点
if(strlen($truncate)$num_单词){
数组\u pop($words\u数组);
$text=内爆($sep,$words\u数组);
$text=$text.$more;
}否则{
$text=内爆($sep,$words\u数组);
}
返回$text;
}
}*

我想知道如何允许在divi主题摘录中使用所有html标记和样式。我了解到divi使用的不是普通的摘录函数,而是truncate post函数

function et_wp_trim_words( $text, $num_words = 55, $more = null ) {
    if ( null === $more )
        $more = esc_html__( '…' );
    // Completely remove icons so that unicode hex entities representing the icons do not get included in words.
    $text = preg_replace( '/<span class="et-pb-icon .*<\/span>/', '', $text );
    $text = wp_strip_all_tags( $text );

    $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
    preg_match_all( '/./u', $text, $words_array );
    $words_array = array_slice( $words_array[0], 0, $num_words + 1 );
    $sep = '';

    if ( count( $words_array ) > $num_words ) {
        array_pop( $words_array );
        $text = implode( $sep, $words_array );
        $text = $text . $more;
    } else {
        $text = implode( $sep, $words_array );
    }

    return $text;
}