Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Manually adding entries to the table of contents #148

Open
dajana91 opened this issue Jan 8, 2023 · 2 comments
Open

Manually adding entries to the table of contents #148

dajana91 opened this issue Jan 8, 2023 · 2 comments

Comments

@dajana91
Copy link

dajana91 commented Jan 8, 2023

Hi,

there seems to be nowhere to reach the plugin author, the support forum is completely neglected. I'm looking for a way to add individual entries at the bottom of the table of contents via functions.php, for example. And in such a way that they integrate seamlessly with an existing table of contents.

Why? Because, for example, I use individual fields that I fill in when I create a post. But these fields or outputs are not part of the "content" section of the post, so they are not captured by the Table of Contents plugin.

So I want to add manually via functions.php to this table below e.g. two entries and also use the links (in this case very specific anchor points, starting with #, e.g. #example) specifically. Ideally, of course, with appropriate numbering. Per functions.php I want to read out whether the specific field was filled - if so, the link in the table of contents should be set accordingly. I then solve this in the functions.php via IF query.

Example:

  1. Headline 1
  2. Headline 2
  3. Headline 3
  4. individual link (a specific anchor like #example)
  5. individual link (a specific anchor like #anotherexample)

Possible? How?

@zedzedzed
Copy link
Owner

zedzedzed commented Jan 15, 2023

Hello

Why? Because, for example, I use individual fields that I fill in when I create a post. But these fields or outputs are not part of the "content" section of the post, so they are not captured by the Table of Contents plugin.

The extra fields need to hook into the_content for it to be picked up by this plugin. If it's not appearing, then my guess is that the_content is not being used here.

So I want to add manually via functions.php to this table

As this sounds like content, I highly recommend you leave your content in the content editor so you can easily manage it via the administration interface wherever and whenever you want.

That said, you can append content to a page using functions.php but it would get messy as you need to target which page to show the content. Here's a snippet that should work for post id 100:

add_filter( 'the_content', function( $content ) {
  global $wp_query;
  $new_content = '';

  if ( 100 === (int) $wp_query->post->ID ) {
    $new_content .= $content .
      '<h4>Example</h4><p>extra content</p>' .
      '<h4>Another Example</h4><p>more extra content</p>'
    ;
  }

  return $new_content;
});

Yes this is quite an edge case.

@dajana91
Copy link
Author

Hello, no, the image gallery and the video gallery should not belong to "the_content", but necessarily separately from it directly below the content. However, the image gallery and video gallery both have anchor points that I can display directly via button by e.g. link#imagegallery. But this image gallery or video gallery is ONLY displayed if the article actually has an image gallery or video gallery. This is practically a bonus to the article. And I would like to add these two items separately in the table of contents below (name and the link I would like to define myself, so it would be ideal via functions.php of course).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants