Syntax highlighted code blocks for WordPress.
Highlighted Code Blocks is a lightweight WordPress plugin that provides syntax highlighting for code blocks built using highlight.js. It aims to improve code readability both in the editor preview are on the front-end.
- Syntax highlighting for code blocks using highlight.js.
- Support for multiple languages.
- Theme support, easily switch any highlight.js themes.
- Minimal configuration, activate and it works.
- Structured using a namespaced plugin class and an autoloader for easy extension.
- Copy the plugin directory
highlight-code-blocksinto your site's plugins directory:wp-content/plugins/highlight-code-blocks/
- Activate the plugin from the WordPress admin: Plugins → Installed Plugins → "Highlighted Code Blocks" → Activate.
- If installing from GitHub, you can clone the repo into the plugins folder:
git clone https://github.com/DarkMatter-999/Syntax-Highlighted-Code-blocks.git wp-content/plugins/highlight-code-blocks
If you're installing or developing the plugin from the GitHub repository, the plugin may include front-end assets (CSS/JS) that need to be built before use. The standard workflow is to install Node dependencies and run the build script which outputs production-ready assets into the plugin directory.
# Clone the repository (optional location)
git clone https://github.com/DarkMatter-999/Syntax-Highlighted-Code-blocks.git highlighted-code-blocks
cd highlighted-code-blocks
# Install dependencies
composer install
npm install
# Build production assets
npm run build
# After build, install/copy the plugin into your site's plugins directory or activate from development site
# If you work directly in wp-content/plugins, run the build there so assets are in-place.
Notes:
- Node.js and npm: use a reasonably recent Node.js LTS (e.g. 16.x, 18.x or later) and matching npm. Check
package.jsonfor any specific engine requirements. - The
npm run buildcommand should produce optimized CSS/JS in the plugin'sbuildordistfolder (or wherever the project is configured to output assets). Ensure those files are present and enqueued by the plugin. - For local development with a watch mode (if provided), use
npm run startor the project's equivalent to rebuild on file changes.
- Add a Code block in the block editor.
- Enter your code and, when available, set the language in the block's settings.
- The plugin will apply syntax highlighting on the front-end. If your editor or theme supports preview of block markup, you may also see enhanced highlighting in the editor preview.
Notes:
- Highlighting depends on the block storing or providing a language attribute. If a language is not specified, highlighting may be generic or absent.
Entry point:
highlight-code-blocks/highlighted-code-blocks.php
This file:
- Defines plugin constants:
HCB_PLUGIN_PATHHCB_PLUGIN_URL
- Loads the autoloader:
include/helpers/autoloader.php
- Bootstraps the plugin:
DM_Highlighted_Code_Blocks\Plugin::get_instance()
Code organization:
- The plugin uses a namespaced structure under
DM_Highlighted_Code_Blocks. Look in theinclude/folder for core classes, blocks, assets enqueuing, and utilities. - Follow WordPress coding standards and best practices when extending or modifying the plugin.
- Prefer adding features via separate extensions or a custom plugin rather than editing core plugin files directly to make updates easier.
If highlighting does not appear or behaves incorrectly:
- Confirm the plugin is active in the WordPress admin.
- Ensure the code block has a language attribute (if the block supports it).
- Check the page source for plugin assets (CSS/JS) being enqueued.
- Clear caches (page cache, object cache, CDN) after activation.
- Temporarily switch to a default theme and disable other plugins to isolate conflicts.
- Look at browser console for JS errors that might prevent syntax highlighter initialization.
If you encounter a bug, include:
- WordPress version
- PHP version
- Theme name
- Steps to reproduce
- Any console errors or server logs
Open an issue on the repository with the details above.
Contributions are welcome. Please follow repository guidelines if available:
- Fork the repo and create a feature branch.
- Follow WordPress PHP and JavaScript coding standards.
- Include clear commit messages and update README or inline docs as needed.
- Submit a pull request with a description of changes and rationale.
This plugin is released under the GNU General Public License v2 (or later).
- Initial release: basic syntax highlighting for code blocks, autoloader and main plugin bootstrap.