AriTOC shortcode, block and hooks reference

The [aritoc] shortcode attributes, block attributes, template functions, filters, JavaScript events and CSS properties.

  • Reference
  • AriTOC
  • 4 min read
  • Updated

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.

AttributeValuesNotes
titleTextTable title.
show_titleyes, noShow the title.
levelsComma-separated levels, such as 2,3 or h2,h3Aliases: headings, heading_levels.
excludeHeadings separated with |, * as wildcardAdded to the site-wide skip list.
min_headings1 to 20Alias: min.
numberingnone, nested, decimal, roman, alpha, bulletsAlias: counter. Also accepts numeric, decimalnested, hierarchical, upper-roman, romannested, lower-alpha, disc, bullet.
themelight, dark, auto, ari, plain, inherit, customcustom uses the colours from the settings page.
widthauto, full, medium
alignnone, center, left, right
hierarchicalyes, noNest sub-headings.
columnsyes, noTwo columns on wide screens.
collapsibleyes, noAlias: toggle.
collapsedyes, noAliases: start_closed, and initial with hide, closed or collapsed.
highlightyes, noHighlight the section being read.
classCSS class names, separated by spacesAdded 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.

AttributeTypeDefault
titlestring""
showTitlestring: "", yes or no""
levelsarray of numbers[]
excludestring""
numberingstring""
themestring""
collapsiblestring: "", yes or no""
collapsedstring: "", yes or no""
hierarchicalstring: "", yes or no""
minHeadingsnumber, 0 = site default0

Template functions

$args takes the same names as the shortcode attributes.

FunctionWhat 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

FilterParametersWhat it filters
aritoc_settings$settingsThe site-wide settings.
aritoc_auto_insert$auto, $postWhether the table is inserted automatically.
aritoc_add_anchors$wanted, $postWhether headings get anchors when no table is in the content.
aritoc_enqueue$wanted, $postWhether to load the stylesheet and script in the head.
aritoc_post_mode$mode, $post_idThe page's mode when none is saved: default, show or hide.
aritoc_reserved_ids$reservedIds a generated anchor never takes.
aritoc_heading$itemOne listed heading: level, id, text, page.
aritoc_anchor$id, $text, $optsA generated anchor before it is made unique.
aritoc_items$items, $argsThe items of one table just before it is built.
aritoc_classes$classes, $argsCSS classes of the table.
aritoc_attributes$attributes, $argsExtra HTML attributes (name => value) of the table.
aritoc_title_after$html, $items, $argsEscaped HTML printed after the title.
aritoc_html$html, $items, $argsThe final table HTML.
aritoc_page_html$html, $post, $numHTML 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-skip on a heading leaves it out.
  • The classes no-toc, aritoc-skip, ez-toc-exclude-headings, lwptoc-skip and simpletoc-hidden always 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:jump fires when a reader clicks an entry that points to a heading on the same page. event.detail has link and target (the heading).
  • aritoc:active fires when the section being read changes. event.detail has link and target, both null above 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.

PropertySet by
--aritoc-bgBackground (Custom colors theme)
--aritoc-fgText (Custom colors theme)
--aritoc-link, --aritoc-actLinks (Custom colors theme)
--aritoc-lineBorder and lines (Custom colors theme)
--aritoc-offsetScroll offset, on :root
--aritoc-mutMuted text such as the item numbers. Set it in your own CSS on .aritoc.
--aritoc-radCorner radius of the box, default 14px. Set it in your own CSS on .aritoc.
--aritoc-gapSpace 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.

KeyWhereWhat
aritoc_settingsOptionAll settings.
_aritoc_modePost metashow or hide.
_aritoc_titlePost metaTitle for this page.
_aritoc_levelsPost metaLevels for this page, such as 2,3.
_aritoc_excludePost metaExtra 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.

Submit a ticketor email info@arihub.com