Other table of contents settings on the page
-
Hi! I have a layout on my site where I would like the table of contents to appear before the first H3 tag. None of the solutions provided in the plugin settings offer this option. I know it can be done manually, but it’s too much work for over 1,000 posts. I’ve tried using a function, but unfortunately, it doesn’t work. Is it possible to automatically place the table of contents in the location I specified, i.e., before the H3 tag? Here is the function:
function custom_insert_toc_before_h3($content) {
if (is_singular() && function_exists('boomdevs_toc')) {
$h3_position = strpos($content, '<h3');
if ($h3_position !== false) {
$before_h3 = substr($content, 0, $h3_position);
$after_h3 = substr($content, $h3_position);
$content = $before_h3 . boomdevs_toc() . $after_h3;
}
}
return $content;
}
add_filter('the_content', 'custom_insert_toc_before_h3');
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- You must be logged in to reply to this topic.