Как разрешить HTML в отрывке записи?

Вот мой код отрывка.

// Создать пользовательскую длину отрывка
function wpbx_excerpt_length($length) {
    return 300;
}
add_filter('excerpt_length', 'wpbx_excerpt_length');

Как мне разрешить HTML-теги? Например: <a> <b> <i> <br>

Понравилась статья? Поделиться с друзьями:
WPAsk
Ответов: 2
  1. Pieter Goosen

    Весь этот код находится в functions.php . Вы можете добавить это чуть выше if (! Function_exists ('wpse_custom_wp_trim_excerpt')): в вашем functions.php

  2. prosti

    Добавьте больше тегов, если вам нужно, в $allowed_tags = ...

    function _20170529_excerpt($text) {
    $raw_excerpt = $text;
    if ( '' == $text ) {
        //Получить содержание поста.
        $text = get_the_content('');
    
        //Удалить все шорткоды из содержимого.
        $text = strip_shortcodes( $text );
    
        $text = apply_filters('the_content', $text);
        $text = str_replace(']]>', ']]&gt;', $text);
    
        $allowed_tags = '<a>,<b>,<br><i>'; 
        $text = strip_tags($text, $allowed_tags);
    
        $excerpt_word_count = 55; /*** измените количество слов отрывка на любое целое число, которое вам нравится.***/
        $excerpt_length = apply_filters('excerpt_length', $excerpt_word_count); 
    
        $excerpt_end = '[...]'; /*** изменить окончание отрывка на что-то другое.***/
        $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end);
    
        $words = preg_split("/[nrt ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
        if ( count($words) > $excerpt_length ) {
            array_pop($words);
            $text = implode(' ', $words);
            $text = $text . $excerpt_more;
        } else {
            $text = implode(' ', $words);
        }
    }
    return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
    }
    
Добавить ответ

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: