定制 tfrommen/highlightjs 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tfrommen/highlightjs

Composer 安装命令:

composer require tfrommen/highlightjs

包简介

A simple Highlight.js-based syntax highlighter plugin for WordPress.

README 文档

README

Version Status Downloads License

A simple Highlight.js-based syntax highlighter plugin for WordPress.

Installation

Install with Composer:

composer require tfrommen/highlightjs

Or:

  1. Download ZIP.
  2. Upload contents to the /wp-content/plugins/ directory on your web server.
  3. Activate the plugin through the Plugins menu in WordPress.
  4. See syntax highlighting for all code snippets wrapped in <pre><code> tags (e.g., a core/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.

统计信息

  • 总下载量: 2.44k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固