Support » Plugin: Easy Table of Contents » Add ToC directly after

Viewing 1 replies (of 1 total)
  • Answering my own question, it appears there is no shortcode in this plugin. So changing the aforementioned function is a no go, unforunately.

    Luckily, Table of Contents Plus does provide a shortcode, so add to your ‘site specific plugin’:

    add_filter( 'the_content', 'saotn_insert_post_toc' );
    function saotn_insert_post_toc( $content ) {
        if ( is_single() && !is_admin() && get_post_type() === 'post' ) {
            return saotn_insert_toc_after_first_p( $content );
        }
        return $content;
    }
    function saotn_insert_toc_after_first_p( $content ) {
        $closing_p = '</p>';
        $paragraphs = explode( $closing_p, $content );
    	foreach ($paragraphs as $index => $paragraph) {
    		$paragraphs[$index] .= $closing_p;
    		if ( in_array($index, array(1)) ) {
    			$paragraphs[$index] .= do_shortcode("[toc]");
    		}
    	}
        return implode( '', $paragraphs );
    }

    Please re-introduce shortcodes.

Viewing 1 replies (of 1 total)
  • The topic ‘Add ToC directly after’ is closed to new replies.