tfrommen / highlightjs
A simple Highlight.js-based syntax highlighter plugin for WordPress.
Installs: 2 156
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Language:JavaScript
Type:wordpress-plugin
Requires
- php: >=7.4
README
A simple Highlight.js-based syntax highlighter plugin for WordPress.
Installation
Install with Composer:
composer require tfrommen/highlightjs
Or:
- Download ZIP.
- Upload contents to the
/wp-content/plugins/
directory on your web server. - Activate the plugin through the Plugins menu in WordPress.
- See syntax highlighting for all code snippets wrapped in
<pre><code>
tags (e.g., acore/code
block).
Requirements
This plugin requires PHP 7.4 or higher.
Usage
Please refer to the Highlight.js documentation.
Filters
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.
\tfrommen\HighlightJs\FILTER_SHOULD_LOAD
(highlightjs.should_load
)
This filter lets you customize the condition for the plugin to load.
The default value is the result of is_singular( 'post' ) && has_block( 'code' )
, meaning the plugin only loads for single posts that include at least one core/code
block.
If you want to load the plugin for all single posts, no matter what blocks are included in the content:
<?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, function () { return is_singlular( 'post' ); } );
If you want to load the plugin for all requests, you can use the __return_true
WordPress function:
<?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' );
License
Copyright (c) 2017 Thorsten Frommen
This code is licensed under the MIT License.
The included Highlight.js is released under the BSD License.