AriTOC has a shortcode, a block, a widget, template functions, filters, one action and a small JavaScript API. It has no REST routes of its own and no WP-CLI commands.
Shortcode
[aritoc] places the table. Every attribute is optional; anything you leave out uses the settings page. Invalid values are ignored. For yes/no attributes, 1, yes, true, on, show and open mean yes; anything else means no.
| Attribute | Values | Notes |
|---|---|---|
title | Text | Table title. |
show_title | yes, no | Show the title. |
levels | Comma-separated levels, such as 2,3 or h2,h3 | Aliases: headings, heading_levels. |
exclude | Headings separated with |, * as wildcard | Added to the site-wide skip list. |
min_headings | 1 to 20 | Alias: min. |
numbering | none, nested, decimal, roman, alpha, bullets | Alias: counter. Also accepts numeric, decimalnested, hierarchical, upper-roman, romannested, lower-alpha, disc, bullet. |
theme | light, dark, auto, ari, plain, inherit, custom | custom uses the colours from the settings page. |
width | auto, full, medium | |
align | none, center, left, right | |
hierarchical | yes, no | Nest sub-headings. |
columns | yes, no | Two columns on wide screens. |
collapsible | yes, no | Alias: toggle. |
collapsed | yes, no | Aliases: start_closed, and initial with hide, closed or collapsed. |
highlight | yes, no | Highlight the section being read. |
class | CSS class names, separated by spaces | Added to the table. |
Block
The block is aritoc/toc, titled “Table of Contents (AriTOC)”. It renders on the server, and an empty value means the site setting. The block's Additional CSS class(es) are added to the table; in a template or widget area without one, the table gets the class aritoc--sidebar.
| Attribute | Type | Default |
|---|---|---|
title | string | "" |
showTitle | string: "", yes or no | "" |
levels | array of numbers | [] |
exclude | string | "" |
numbering | string | "" |
theme | string | "" |
collapsible | string: "", yes or no | "" |
collapsed | string: "", yes or no | "" |
hierarchical | string: "", yes or no | "" |
minHeadings | number, 0 = site default | 0 |
Template functions
$args takes the same names as the shortcode attributes.
| Function | What it does |
|---|---|
aritoc( $args = array() ) | Prints the table of the current post. |
aritoc_get( $args = array(), $post = null ) | Returns the table HTML for a post (ID or WP_Post; defaults to the current one). |
aritoc_get_headings( $post = null ) | Returns the headings found: a list of arrays with level, id, text, page, and url for headings on other pages of a paginated post. |
<?php
if ( function_exists( 'aritoc' ) ) {
aritoc( array( 'levels' => '2,3', 'theme' => 'plain' ) );
}
?>
Filters
| Filter | Parameters | What it filters |
|---|---|---|
aritoc_settings | $settings | The site-wide settings. |
aritoc_auto_insert | $auto, $post | Whether the table is inserted automatically. |
aritoc_add_anchors | $wanted, $post | Whether headings get anchors when no table is in the content. |
aritoc_enqueue | $wanted, $post | Whether to load the stylesheet and script in the head. |
aritoc_post_mode | $mode, $post_id | The page's mode when none is saved: default, show or hide. |
aritoc_reserved_ids | $reserved | Ids a generated anchor never takes. |
aritoc_heading | $item | One listed heading: level, id, text, page. |
aritoc_anchor | $id, $text, $opts | A generated anchor before it is made unique. |
aritoc_items | $items, $args | The items of one table just before it is built. |
aritoc_classes | $classes, $args | CSS classes of the table. |
aritoc_attributes | $attributes, $args | Extra HTML attributes (name => value) of the table. |
aritoc_title_after | $html, $items, $args | Escaped HTML printed after the title. |
aritoc_html | $html, $items, $args | The final table HTML. |
aritoc_page_html | $html, $post, $num | HTML of another page of a paginated post before its headings are read. |
Action
aritoc_assets fires once when AriTOC loads its front-end stylesheet and script on a page, so an add-on can load its own files.
Heading attributes and classes
data-aritoc-label="Short label"on a heading shows that label in the table.data-aritoc-skipon a heading leaves it out.- The classes
no-toc,aritoc-skip,ez-toc-exclude-headings,lwptoc-skipandsimpletoc-hiddenalways leave a heading out.
JavaScript
The front-end script needs no jQuery. Each table is a nav element with the attribute data-aritoc.
window.AriTOC.init( element )activates a table added to the page later.aritoc:jumpfires when a reader clicks an entry that points to a heading on the same page.event.detailhaslinkandtarget(the heading).aritoc:activefires when the section being read changes.event.detailhaslinkandtarget, bothnullabove the first heading.
document.addEventListener( 'aritoc:active', function ( e ) {
if ( e.detail.target ) {
console.log( 'Reading: ' + e.detail.target.id );
}
} );
Both events bubble from the table's nav element.
CSS custom properties
The Custom colors theme sets these on the table's nav element. You can also set them in your own CSS on .aritoc.
| Property | Set by |
|---|---|
--aritoc-bg | Background (Custom colors theme) |
--aritoc-fg | Text (Custom colors theme) |
--aritoc-link, --aritoc-act | Links (Custom colors theme) |
--aritoc-line | Border and lines (Custom colors theme) |
--aritoc-offset | Scroll offset, on :root |
--aritoc-mut | Muted text such as the item numbers. Set it in your own CSS on .aritoc. |
--aritoc-rad | Corner radius of the box, default 14px. Set it in your own CSS on .aritoc. |
--aritoc-gap | Space between items, default .3em. Set it in your own CSS on .aritoc. |
Stored data
The post meta is registered for the REST API, so the block editor can read it; only users who can edit the post can change it.
| Key | Where | What |
|---|---|---|
aritoc_settings | Option | All settings. |
_aritoc_mode | Post meta | show or hide. |
_aritoc_title | Post meta | Title for this page. |
_aritoc_levels | Post meta | Levels for this page, such as 2,3. |
_aritoc_exclude | Post meta | Extra headings to skip, separated with |. |
Still stuck?
Our helpdesk answers on working days, Norwegian time. Include your WordPress version, PHP version, AriTOC version and the page address.