WordPress.org

Ready to get started?Download WordPress

Forums

Table of Contents Plus
[resolved] Using a shortcode with TOC+ (7 posts)

  1. computerslayer1
    Member
    Posted 1 year ago #

    I use a custom shortcode in a page. This shortcode displays an h2 tag, followed by paragraphs of text.

    If TOC+ is enabled for pages, it sets the h2's span ID to all the text in the custom shortcode that follows the first h2 tag. Additionally, the #toc_list element's anchors display all the text that follows the h2 tag in the custom shortcode as well.

    As you can imagine, it looks like quite a mess.

    Is there a way to fix this?

    Thanks :)

    http://wordpress.org/extend/plugins/table-of-contents-plus/

  2. Mike
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks for raising that.

    I would suggest to check if the custom shortcode closes the h2 tag properly after the actual heading. TOC+ reads the text between the heading tags so make sure they are closed properly.

    If the above doesn't work, add a newline (eg echo "\n") at the end of your headings as TOC+ shouldn't match anything over multiple lines.

  3. computerslayer1
    Member
    Posted 1 year ago #

    Yep, properly formed HTML. Here's an example of the output:

    <h2>My Heading</h2><div class="grid"><div><img src="example.org/spacer.gif" width="90" height="113"><p><a href="#">Some text 2</a></p><p>Even more text 2</p><p>987654321</p></div><div><img src="example.org/spacer.gif" width="90" height="113"><p><a href="#">Some text</a></p><p>Even more text</p><p>12345678</p></div></div>

    Adding a new line character didn't seem to have an effect.

  4. computerslayer1
    Member
    Posted 1 year ago #

    Here's what I get for output with the TOC+ plugin:

    The HTML that appears in the h2 tag:
    <h2><span id="My_Heading_____Some_text_2___Even_more_text_2___987654321_____Some_text___Even_more_text___12345678">My Heading</span></h2>

    The HTML that appears in the #toc_list:

    <ul class="toc_list">
    <li><a href="#My_Heading_____Some_text_2___Even_more_text_2___987654321_____Some_text___Even_more_text___12345678">My_Heading_____Some_text_2___Even_more_text_2___987654321_____Some_text___Even_more_text___12345678</a></li>
    </ul>
  5. Mike
    Member
    Plugin Author

    Posted 1 year ago #

    That's interesting. Are you able to add a newline after the closing heading tag to see if it does the same thing?

    Next up, I'm most likely going to ask for the custom php stuff sitting behind the shortcode so I can try on one of my machines. Is it another plugin you wrote or did you do it via functions.php?

  6. computerslayer1
    Member
    Posted 1 year ago #

    My mistake--I forgot to copy the plugin file from my IDE to the website after I made the change. So, yes, adding a new line after the closing header element seems to work.

  7. Mike
    Member
    Plugin Author

    Posted 1 year ago #

    Awesome, thanks for reporting back.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.