skip to Main Content

I found a tutorial online which shows how to use a table of content in WordPress. There is a code and the code is

if ( is_page( 'tocbot' ) ) {

    wp_enqueue_script(
        'tocbot',
        plugin_dir_url( __FILE__ ) . 'assets/js/tocbot.min.js',
        array(),
        '4.3.1',
        true
    );

} // End if().

The developer said that we need to replace is_page( ‘tocbot’ ) with your desired if conditional depending on where you want to use Tocbot.

I found the tutorial here

2

Answers


  1. Use is_sgingle() insted of is_page().

    if ( is_sgingle() ) {
    
        wp_enqueue_script(
            'tocbot',
            plugin_dir_url( __FILE__ ) . 'assets/js/tocbot.min.js',
            array(),
            '4.3.1',
            true
        );
    
    } // End if().
    
    Login or Signup to reply.
  2. List of all WordPress conditionals is here.

    In your case for all posts it is will be is_single. For posts, pages and post types it is is_singular.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search