Я пытаюсь вставить шорткод [toc], но делаю что-то не так, потому что не работает.
- Я пробовал
$new_content .= do_shortcode ('[toc]');
БЕЛАЯ страница - Я пробовал
$new_content .= '[toc]';
БЕЛАЯ страница - Если я поставлю
$new_content .= '<span>gg</span>';
ЭТО РАБОТАЕТ.
Плагин - простое оглавление
Я использую этот код в функциях. php
function insert_ad_in_content($content)
{
if ((!is_singular('post')) || (strpos($content, '<h2') === FALSE) ) { return $content; }
$ChapterCount = 2; // Enter the chapter number, which you'd like an add in front of
$content = explode("<h2", $content);
$new_content = '';
for ($i = 0; $i < count($content); $i++) {
if ($i == $ChapterCount) {
$new_content .= do_shortcode('[toc]');
}
if($i>0) {
$new_content.= "<h2".$content[$i];
} else {
$new_content.= $content[$i];
}
}
return $new_content;
}
add_filter('the_content', 'insert_ad_in_content');