• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to user navigation

PopWP

WordPress and Genesis Tutorials

  • Get Started
  • About
  • Archive
  • Services
  • Membership
  • My Account

Table of contents using Tocbot in Genesis

Last Updated on March 7, 2020 Favorited: 0 times

This tutorial provides the steps to add table of contents(TOC) on singular post and page using Tocbot inany child theme based on Genesis Framework.

This will also work on other WordPress themes with minor changes.

Prerequisite:-

  1. Download the Tocbot files and extract in your computer. Path https://github.com/tscanlin/tocbot/tree/master/dist
  2. Copy tocbot.js and tocbot.css in the relative folder of your child-theme. The path will go like this child-theme/js/tocbot.js for JS file and child-theme/css/tocbot.css

You can copy the tocbot.css file code directly in the child-theme/style.css file.

Remember, We are going to first work on single post using conditional tag. Make sure Post headings have id attributes to make the tocbot scroll to the right heading. You can use Plugin https://wordpress.org/plugins/add-ids-to-header-tags

STEP 1

Let's first thing we do is to enqueue the tocbot.css and tocbot.js Add the required snippet in functions.php of your child theme.

//* Load tocbot script and styles
add_action( 'wp_enqueue_scripts', 'custom_tocbot_script_style' );
function custom_tocbot_script_style() {
	if ( ! is_singular('post') ) {
		return;
	}
  wp_enqueue_style( 'tocbot-style', get_stylesheet_directory_uri() . '/css/tocbot.css', array(), '1.0.0' );
  wp_enqueue_script( 'tocbot-script', get_stylesheet_directory_uri() . '/js/tocbot.js', array( 'jquery' ),  '1.0.0' );
}

remove this line if you pasted tocbot.css code in style.css

  wp_enqueue_style( 'tocbot-style', get_stylesheet_directory_uri() . '/css/tocbot.css', array(), '1.0.0' );

STEP 2

Init the tocbot script to build a table of contents. Add the required code in functions.php

To view the full content, please sign up for the membership.

Already a member? Log in below or here.

 
 
Forgot Password

Categories: Genesis Tutorials, Premium Content Tags: toc, tocbot

Primary Sidebar

Search

WPEngine WordPress Hosting, Perfected.

Hosting You are looking for?.
Perfect solution for small business to global enterprise.

Learn more

StudioPress Genesis Theme Framework

The No.1 Theme Provider.
Creative, SEO rich Theme for all niche projects.

Learn more

Categories

  • Free Content
  • Genesis Tutorials
  • Premium Content
  • Snippets
  • What's New?
  • WordPress Tutorials

Tag Cloud

Archive Background Section blog canvas menu center logo columns conditional tags CSS CSS Grid custom Customizer custom post type Custom Post Types custom template Custom Widget effect eNews Extended Featured Image front-page Genesis Genesis Sample header right hero section Image Background js layout left menu Logo menu Navigation Menu newsletter post page related posts responsive menu search search widget Shrinking Logo site header slide in-out Stylesheet Template Utility Bar Video Background widgets WordPress

Built with Genesis Framework + WordPress by Aryan Raj

  • Contact
  • FAQ
  • Disclaimer
  • Privacy Policy
  • Copyright Policy
  • Terms of Service