Table of Contents
This feature will create a checkbox inside any post type or page that will show a Table of Contents in the front-end. It gathers all the H2 and H3 and adds them at the top of the page. Each heading has an anchor link to the title of the content.
With the code below you can change the title and also translate it:
// Change TOC title
function my_custom_toc_title($title) {
if (defined('ICL_LANGUAGE_CODE')) {
$translations = [
'el' => 'Περιεχόμενα',
'en' => 'Article Contents',
];
return $translations[ICL_LANGUAGE_CODE] ?? $title;
} else {
$title = 'Article Contents';
}
return $title;
}
add_filter('custom_toc_title', 'my_custom_toc_title');