Below, you’ll find a detailed guide on how to add the LuckyWP Table of Contents Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the LuckyWP Table of Contents Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the LuckyWP Table of Contents Plugin and the shortcodes it provides:
"LuckyWP Table of Contents is a powerful WordPress plugin that allows you to create organized, user-friendly content with dynamic, easy-to-navigate tables for improved readability."
- [luckywp_table_of_contents]
LuckyWP Table of Contents [luckywp_table_of_contents] Shortcode
The LuckyWP Table of Contents shortcode is a powerful tool that generates a table of contents for your WordPress post. It dynamically fetches headings from your post and presents them in a structured manner. It checks if the plugin is activated and if the content is allowed. If it is, it processes the post’s settings and attributes. This includes settings like ‘min’, ‘depth’, ‘hierarchical’, ‘numeration’, and more. The shortcode then generates the table of contents based on these settings. It also handles skipping certain heading levels and texts as per the plugin’s settings. In essence, it enhances navigability and structure in your post.
Shortcode: [luckywp_table_of_contents]
Parameters
Here is a list of all possible luckywp_table_of_contents shortcode parameters and attributes:
min
– Minimum number of headings to show the tabledepth
– Depth of the table of contentshierarchical
– Determines if the table is hierarchicalnumeration
– Type of numeration for the tablenumerationSuffix
– Suffix for numerationtitle
– Title of the table of contentstoggle
– Option to toggle visibility of the tablelabelShow
– Label for the ‘show’ buttonlabelHide
– Label for the ‘hide’ buttonhideItems
– Option to hide items initiallysmoothScroll
– Enables smooth scrollingsmoothScrollOffset
– Offset for smooth scrollingwidth
– Width of the table of contentsfloat
– Floats the table to left, right or nonetitleFontSize
– Font size of the titletitleFontWeight
– Font weight of the titleitemsFontSize
– Font size of the itemscolorScheme
– Color scheme of the tablebackgroundColor
– Background color of the tableborderColor
– Border color of the tabletitleColor
– Color of the titlelinkColor
– Color of the linkshoverLinkColor
– Color of the links on hovervisitedLinkColor
– Color of visited linkswrapNoindex
– Wraps the table in noindex tagsuseNofollow
– Adds nofollow to linksskipHeadingLevel
– Skips a specific heading levelskipHeadingText
– Skips headings with specific textcontainerClass
– Adds a specific class to the table container
Examples and Usage
Basic example – Displays a table of content for a post or a page using its ID.
[luckywp_table_of_contents id=1 /]
Advanced examples
Display a table of content with a specific depth and hierarchical structure. The ‘min’ attribute sets the minimum number of headings to display the table of contents, ‘depth’ attribute sets the maximum level of headings to include in the table of contents, and ‘hierarchical’ attribute enables or disables hierarchical view.
[luckywp_table_of_contents id=1 min=3 depth=6 hierarchical=true /]
Display a table of content with customized title and numeration. The ‘title’ attribute sets the title of the table of contents, ‘numeration’ attribute sets the type of numeration, and ‘numerationSuffix’ attribute sets the character or string after the numeration.
[luckywp_table_of_contents id=1 title="Table of Contents" numeration="decimal" numerationSuffix="." /]
Display a table of content with custom colors. The ‘backgroundColor’ attribute sets the background color of the table of contents, ‘borderColor’ attribute sets the border color, and ‘titleColor’, ‘linkColor’, ‘hoverLinkColor’, ‘visitedLinkColor’ attributes set the color of the title, links, hovered links, and visited links respectively.
[luckywp_table_of_contents id=1 backgroundColor="#f5f5f5" borderColor="#ddd" titleColor="#333" linkColor="#007bff" hoverLinkColor="#0056b3" visitedLinkColor="#6c757d" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [luckywp_table_of_contents]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode($this->getTag(), [$this, 'shortcode']);
Shortcode PHP function:
function shortcode($attrs)
{
global $post;
if ($this->isDiactivated() ||
($this->theContentApplied && $this->headingsCache === null) ||
!static::allow()
) {
return '';
}
$attrs = ValueHelper::assertArray($attrs);
if ($post instanceof WP_Post) {
$postSettings = new PostSettings($post->ID);
if ($postSettings->enabled || $postSettings->processHeadings) {
foreach ([
'min',
'depth',
'hierarchical',
'numeration',
'numerationSuffix',
'title',
'toggle',
'labelShow',
'labelHide',
'hideItems',
'smoothScroll',
'smoothScrollOffset',
'width',
'float',
'titleFontSize',
'titleFontWeight',
'itemsFontSize',
'colorScheme',
'backgroundColor',
'borderColor',
'titleColor',
'linkColor',
'hoverLinkColor',
'visitedLinkColor',
'wrapNoindex',
'useNofollow',
'skipHeadingLevel',
'skipHeadingText',
'containerClass',
] as $var) {
if (!array_key_exists(strtolower($var), $attrs) &&
$postSettings->$var !== null
) {
$attrs[strtolower($var)] = $postSettings->$var;
}
}
}
}
if (Core::$plugin->isTheContent) {
return $this->make($attrs, true);
}
if (!$this->theContentApplied) {
$this->skipLevels[] = Core::$plugin->skipHeadingLevelToArray(array_key_exists('skipheadinglevel', $attrs) ? $attrs['skipheadinglevel'] : Core::$plugin->settings->getMiscSkipHeadingLevel());
$this->skipText[] = Core::$plugin->skipHeadingTextToArray(array_key_exists('skipheadingtext', $attrs) ? $attrs['skipheadingtext'] : Core::$plugin->settings->getMiscSkipHeadingText());
}
if ($this->headingsCache === null) {
$dto = $this->makeContentHandlingDto();
$dto->modify = false;
$this->isTheContentEmulate = true;
$dto->content = apply_filters('the_content', $post->post_content);
$this->isTheContentEmulate = false;
$this->headingsCache = ContentHandling::go($dto)->headings;
}
return Toc::render($this->headingsCache, $attrs);
}
Code file location:
luckywp-table-of-contents/luckywp-table-of-contents/plugin/Shortcode.php
Conclusion
Now that you’ve learned how to embed the LuckyWP Table of Contents Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply