Я использую wp_trim_words, чтобы обрезать некоторые отрывки на моей домашней странице. Он работает нормально, за исключением того, что из отрывков удаляются теги HTML. Мне нужно иметь возможность выделять определенные фрагменты отрывка жирным шрифтом (с помощью ). Следуя инструкциям здесь, я попытался удалить функцию wp_trim_words и заменить ее новой, используя следующий код, который заменяет $text = wp_strip_all_tags( $text); из исходной функции WP на $text = Strip_tags($ текст, '',);. Но это ломает сайт. Что я делаю не так?
// Remove Reverie Trim Words
function remove_trim_words() {
remove_filter('get_the_excerpt', 'wp_trim_words');
add_filter('get_the_excerpt', 'oakwood_trim_words');
}
// Replace Reverie Trim Words
function oakwood_trim_words( $text, $num_words = 55, $more = null ) {
if ( null === $more )
$more = __( '…' );
$original_text = $text;
$text = strip_tags($text, '',);
/* translators: If your word count is based on single characters (East Asian characters),
enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */
if ( 'characters' == _x( 'words', 'word count: words or characters?' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) {
$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 = '';
} else {
$words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY );
$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 );
}
/**
* Filter the text content after words have been trimmed.
*
* @since 3.3.0
*
* @param string $text The trimmed text.
* @param int $num_words The number of words to trim the text to. Default 5.
* @param string $more An optional string to append to the end of the trimmed text, e.g. ….
* @param string $original_text The text before it was trimmed.
*/
return apply_filters( 'oakwood_trim_words', $text, $num_words, $more, $original_text );
}
Подробнее здесь: https://stackoverflow.com/questions/241 ... in-excerpt
Как запретить Wordpress удалять HTML-теги в отрывке ⇐ Php
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как запретить ASP.NET CheckboxList удалять себя, если в нем нет элементов?
Anonymous » » в форуме C# - 0 Ответы
- 12 Просмотры
-
Последнее сообщение Anonymous
-