highlight.js Syntax Highlighter
A simple highlight.js-based syntax highlighter plugin for WordPress.
Install with Composer:
$ composer require tfrommen/highlightjs
- Download ZIP.
- Upload contents to the
/wp-content/plugins/directory on your web server.
- Activate the plugin through the Plugins menu in WordPress.
- Include code snippets wrapped in
This plugin requires PHP 5.4 or higher, but you really should be using PHP 7 or higher, as we all know.
Please refer to the highlight.js documentation.
In order to customize certain aspects of the plugin, it provides you with several filters.
For each of these, a short description as well as a code example on how to alter the default behavior is given below.
Just put the according code snippet in your theme's
functions.php file or your customization plugin, or to some other appropriate place.
This filter lets you customize the condition for the plugin to load.
The default value is the result of
is_singular( 'post' ), meaning the plugin only loads for single posts.
<?php /** * Filters the condition for the plugin to load. * * @param bool $should_load Whether or not the plugin should load. */ add_filter( \tfrommen\HighlightJs\FILTER_SHOULD_LOAD, '__return_true' );
Copyright (c) 2017 Thorsten Frommen
This code is licensed under the MIT License.
The included highlight.js is released under the BSD License.