Hi There,
You need to override the [toc_item]
shortcode by setting up a child theme: https://theme.co/apex/forum/t/setup-how-to-setup-child-themes/57.
After that adding the following code under functions.php
file locates in your child theme:
add_action('wp_head', 'change_toc_item_shortcode');
function change_toc_item_shortcode() {
remove_shortcode( 'x_toc_item' );
remove_shortcode( 'toc_item' );
add_shortcode( 'toc_item', 'x_shortcode_toc_item_v2' );
add_shortcode( 'x_toc_item', 'x_shortcode_toc_item_v2' );
}
function x_shortcode_toc_item_v2( $atts ) {
extract( shortcode_atts( array(
'id' => '',
'class' => '',
'style' => '',
'title' => '',
'page' => '',
'link_item' => ''
), $atts, 'x_toc_item' ) );
$id = ( $id != '' ) ? 'id="' . esc_attr( $id ) . '"' : '';
$class = ( $class != '' ) ? 'x-toc-item ' . esc_attr( $class ) : 'x-toc-item';
$style = ( $style != '' ) ? 'style="' . $style . '"' : '';
$title = ( $title != '' ) ? $title : '';
$link_item = ( $link_item != '' ) ? $link_item : '';
switch ( $page ) {
case 0 :
$page = '';
break;
case 1 :
$page = '';
break;
default :
$page = $page;
if ( get_post_status( get_the_ID() ) == "draft" ) {
$page = '&page=' . $page;
} else {
$page = ( get_the_ID() == get_option( 'page_on_front' ) ) ? 'page/' . $page . '/' : $page . '/';
}
}
$link = $link_item ? $link_item : esc_url( get_permalink() ) . $page;
$output = "<li {$id} class=\"{$class}\" {$style}><a href=" . $link . " title=\"Go to {$title}\">" . $title . '</a></li>';
return $output;
}
Then the shortcodes should be like this:
[toc title="Table of Contents" type="left"] [toc_item title="1. Introduction" page="1" link_item="http://www.google.com"] [toc_item link_item="http://www.google1.com" title="2. More Information" page="2"] [toc_item title="3. Even More Information" link_item="http://www.google2.com" page="3"] [/toc]
Let us know if this code works for you.