How Do I Add a Floating Table of Contents in WordPress?

Adding a floating table of contents in WordPress is easy. First, create a new file in your themes directory named _header.

php. This file will contain the code that creates the table of contents.

In the _header.php file, add the following code:

Now, in the header.php file, add the following line to create the table of contents:

Finally, in the header.php file, add the following line to display the table of contents:

That’s it! Your table of contents will now be displayed in the header of your website.