wp: back to toc


I found a nice plugin for adding a table of contents to a post (like the wiki pages have)

However it had one limitation, there is no back to top link. Since we want to go back to the toc (which can be at the top / bottom), Ive called it the back_to_toc feature.

It has 3 options – not to show / show text / show image.

See snippets overleaf or explore the  code (line 559 of toc.php is where the real changes start). Or view it in action.


The plugin filters the the_content method and the code added to it is


//Line 560
$btt = "";
if ($this->options['back_to_toc'] != TOC_BACKTOTOC_NONE)
	$img = $this->options['back_to_toc'] == TOC_BACKTOTOC_IMG;
	$bttText = $img ? " " : "top"; //space else image doesnt show
	$bttSuffix = $img ? "_img" : "";
	$btt = '' . $bttText . '';

//Line 617
if ($this->options['back_to_toc'] != TOC_BACKTOTOC_NONE)
	$html = '' . $html;


a.toc_to_top { float: right; color: #444; } a.toc_to_top:hover { color: #C04242; }
a.toc_to_top_img { float: right; background: url(back_to_top.png) no-repeat left center; width: 40px; }
a.toc_to_top, a.toc_to_top_img { text-decoration: none; }


Warning: count(): Parameter must be an array or an object that implements Countable in /home/cselian/public_html/blog/wp-includes/class-wp-comment-query.php on line 405

Comments are closed.