Answer the question
In order to leave comments, you need to log in
WordPress. How to automatically wrap blocks before displaying on the page?
Site on WordPress.
Articles often build multi-level lists. Each sublevel must be folded into a spoiler.
There is a solution via JQ:
jQuery('li>ol').wrap('<div class="spoil"><div class="sp_text"></div></div>'); // обернуть
jQuery( '.spoil' ).prepend('<button class="sp_button">Подробности</button>'); // добавить кнопку
Answer the question
In order to leave comments, you need to log in
Solution found. If anyone is interested, then it's done like this.
add_filter('the_content', 'spoilers');
function spoilers( $text ){
$text = preg_replace('/(<\/ol>)(((?!<li.*>|<\/li>|<ol.*>|<\/ol>).)*?)(<\/li>)/s', '$1$2</div></div>$2$4', $text);
$text = preg_replace('/(<li>((?!<li.*>|<\/li>|<ol.*>|<\/ol>).)*?)(<ol>)/s', '$1<div class="spoil"><button class="sp_button>Подробности</button><div class="sp_text">$2$3', $text);
return $text;
You can hook onto the filter the_content
and then wrap it using a regular expression
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question