• Resolved snippet24

    (@snippet24)


    Hi, let me know how to proceed to further debug this. I’m runnin this on local host in a custom theme added by shortcode inside template as follows:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
            <div class="text-justify">
            
            <?php
            echo do_shortcode('[joli-toc]');
            ?>
            <?php the_content(); ?>
            </div>
            <?php endwhile;         
       endif; ?>

    Tried what was suggested here https://www.ads-software.com/support/topic/no-hash-id-added-to-headlines/

    and didn’t fix it.

    • This topic was modified 6 months, 1 week ago by snippet24.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author WPJoli

    (@wpjoli)

    Hi,

    Since your shortcode is generated outside of “the_content” context, it is likely that it won’t be able to pick up on the actual content and that would be why the anchor links are not generated.

    You need to include the TOC to the_content. You can try something like this:

    add_filter('the_content', function ($content) {
        return do_shortcode('[joli-toc]') . $content;
    }, 1);

    Replace your echo do_shortcode('[joli-toc]'); shortcode by the above code.

    Let me know if this gets you anywhere.

    If you still have issue, you may need to adjust the priority number of the function (replace 1 by 5 or 10 for example).

    Thread Starter snippet24

    (@snippet24)

    Hi, I’m afraid it is still not working even using 5 or 10 values instead of 1. Also using that method causes the table of contents to display in every page.. Perhaps this behavior could be improved? for example the older abandoned plugin worked out of the box with the same placement of the corresponding shortcode.

    Regards

    Plugin Author WPJoli

    (@wpjoli)

    Hi,

    I’m not sure what you’re trying to achieve with your custom theme. If you’re hard-coding the TOC in your template, it’s supposed to show whenever the template is called.

    Maybe you should wrap the TOC in a condition to do more fine-tuning.

    Other than that, you can try to activate the Widget support mode and keep your original code. That could do the trick.

    Thread Starter snippet24

    (@snippet24)

    If you’re hard-coding the TOC in your template, it’s supposed to show whenever the template is called.

    Yes that’s what I’m doing.

    Other than that, you can try to activate the Widget support mode and keep your original code. That could do the trick.

    No idea why but that worked!!! Thank you ??

    Plugin Author WPJoli

    (@wpjoli)

    The widget support mode is designed to process the headings whenever the TOC is outside of the_content (in a widget sidebar most of the time).

    Thanks for the feedback!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘No scrolling to heading due to no id present in headings’ is closed to new replies.