Skip to:
Content
Pages
Categories
Search
Top
Bottom

Help needed to adjust function to add TOC to Buddypress Docs using Better Anchor Links plugin

  • Avatar of nickharambee
    nickharambee
    Participant

    @nickharambee

    Hi,

    I have installed the Better Anchor Links plugin, in order to generate a table of contents on my Buddypress Docs pages. I can manually add a TOC at the top of documents using the tag [mwm-aal-display], but I would like to automate this, i.e. any document which uses heading tags (i.e. h1,h2,h3…) will get a TOC at the top.

    In the FAQ for the Better Anchor Links plugin, It states that a PHP tag can also be used, i.e.

    `output_content_links(); ?>`

    But only after `the_content()`. However, if I include it after `the_content()` in the single-doc.php for BP Docs, the TOC shows up at the bottom of the document, which is not what I want.

    I got in touch with Boone, developer of the BuddyPress Docs plugin, and he suggested a couple of functions I could try, which I include below. These did indeed add a TOC automatically, but unfortunately they broke the redirecting back to a document page after editing a document. When clicking save after editing a document, rather than being directed back to the page for the document, the URL for editing the document remained and I just got a blank screen. If I manually edited the URL to point to the document, I could see that the edits that I had just made were intact, so it seems that the issue is just with the redirecting.

    I wonder if anyone can suggest amendments to either of the functions below to get this working?

    Thanks,

    Nick

    FUNCTION 1

    function bbg_add_toc_to_doc( $content ) {
    global $mwm_aal;
    $content = $mwm_aal->output_content_links() . $content;
    return $content;
    }
    add_filter( ‘the_content’, ‘bbg_add_toc_to_doc’ );`

    FUNCTION 2

    `function bbg_add_toc_to_doc( $content ) {
    global $mwm_aal;

    if ( !empty( $mwm_aal ) && is_object( $mwm_aal ) && method_exists( $mwm_aal, ‘output_content_links’ ) )
    $content = $mwm_aal->output_content_links() . $content;

    return $content;
    }
    add_filter( ‘the_content’, ‘bbg_add_toc_to_doc’ );`

You must be logged in to reply to this topic.