Title: Adding shortcode [toc] by code is not running
Last modified: April 7, 2025

---

# Adding shortcode [toc] by code is not running

 *  Resolved [nuriarai](https://wordpress.org/support/users/nuriarai/)
 * (@nuriarai)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/adding-shortcode-toc-by-code-is-not-running/)
 * Hello, I can’t show you a post because I’m still on local development. The issue
   is that if I put this piece of code in my single template (single.php), the shortcode
   is not executed. If I put the shortcode inside the content it runs correctly.
   
   <?php echo do_shortcode( ‘[toc heading_levels=”2″ start=”3″]’ ); ?>But I want
   to put it in a differennt position that those the plugin offers. Isn’t it possible?
   Thanks in advance!
    -  This topic was modified 1 year, 2 months ago by [nuriarai](https://wordpress.org/support/users/nuriarai/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Support [Prabhat](https://wordpress.org/support/users/prabhatrai/)
 * (@prabhatrai)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/adding-shortcode-toc-by-code-is-not-running/#post-18407981)
 * Hi there,
 * Thanks for the details!
 * The reason your current approach isn’t working is because the [toc] shortcode
   doesn’t directly generate the TOC HTML. Instead, it returns a placeholder (<!–
   TOC–>), which gets replaced with the actual TOC later during WordPress’s the_content
   filter processing.
 * Since this filter doesn’t run when you call the shortcode manually in a template,
   the TOC never gets generated in that context.
 * I’d be happy to test and provide you with a custom solution. Please reach out
   to us directly at **[support@aioseo.com](https://wordpress.org/support/topic/adding-shortcode-toc-by-code-is-not-running/support@aioseo.com?output_format=md)**
   so I can assist further.
 * I’m really looking forward to helping you.
 *  [frafor](https://wordpress.org/support/users/frafor/)
 * (@frafor)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/adding-shortcode-toc-by-code-is-not-running/#post-18417164)
 * I am having the same issue but still your reply that doesn’t make any sense: 
   what’s the shortcode intended for if it’s not possible to use it outside of the
   content? I even tried “apply_filters(‘the_content’, do_shortcode(‘[toc]’));” 
   and all I get is a <p></p> tag.
    -  This reply was modified 1 year, 1 month ago by [frafor](https://wordpress.org/support/users/frafor/).
 *  Plugin Support [Prabhat](https://wordpress.org/support/users/prabhatrai/)
 * (@prabhatrai)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/adding-shortcode-toc-by-code-is-not-running/#post-18424467)
 * Hi [@frafor](https://wordpress.org/support/users/frafor/),
 * Currently, we don’t have a shortcode that works when added outside the content
   area.
 * However, as mentioned in my last reply, I’d be happy to test and provide a custom
   solution. In this case, please reach out to us directly at **[support@aioseo.com](https://wordpress.org/support/topic/adding-shortcode-toc-by-code-is-not-running/support@aioseo.com?output_format=md)**
   so I can assist further.
 * Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Adding shortcode [toc] by code is not running’ is closed to new replies.

 * ![](https://ps.w.org/table-of-contents-plus/assets/icon-256x256.png?rev=1151771)
 * [Table of Contents Plus](https://wordpress.org/plugins/table-of-contents-plus/)
 * [Support Threads](https://wordpress.org/support/plugin/table-of-contents-plus/)
 * [Active Topics](https://wordpress.org/support/plugin/table-of-contents-plus/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/table-of-contents-plus/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/table-of-contents-plus/reviews/)

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 3 replies
 * 3 participants
 * Last reply from: [Prabhat](https://wordpress.org/support/users/prabhatrai/)
 * Last activity: [1 year, 1 month ago](https://wordpress.org/support/topic/adding-shortcode-toc-by-code-is-not-running/#post-18424467)
 * Status: resolved