A WordPress plugin that adds Gutenberg blocks to create in-page anchors and display a quick-access navigation list.
Blockparty Anchors is a WordPress plugin that lets editors build an anchor system directly in the block editor. Place Anchor blocks throughout a page, then add an Anchors List block to generate a linked table of contents.
- Two native Gutenberg blocks:
blockparty/anchorandblockparty/anchors-list - Anchor block: Place invisible anchor points on a page with an HTML-friendly
id - Editable labels: Customize anchor titles inline with
RichText - Automatic slug generation: Slugs are derived from the title (e.g.
My anchorβmy-anchor) - Manual slug override: Edit the anchor ID from the block inspector sidebar
- Dynamic anchors list: The list block automatically discovers all Anchor blocks on the current page
- Bidirectional editor sync: Editing a title from the Anchors List block updates the corresponding Anchor block
- Dynamic PHP rendering: Server-side output with theme override support
- Nested block support: Anchors are collected recursively, including inside columns, groups, and other containers
- Object cache: Anchor metadata is cached per post and invalidated on content updates
- Internationalized: Multilingual support with translation files (English and French included)
- WordPress: Version 6.8 or higher
- PHP: Version 8.1 or higher
- PHP Extension: ext-json
- Node.js: Version 24.x (recommended via Volta) for asset development
composer require beapi/blockparty-anchors- Download the latest version of the plugin
- Extract the archive to the
/wp-content/plugins/folder - Activate the plugin from the WordPress "Plugins" menu
# Clone the repository
git clone https://github.com/BeAPI/blockparty-anchors.git
cd blockparty-anchors
# Install PHP dependencies
composer install
# Install JavaScript dependencies
npm install
# Build the assets
npm run build- Open the Gutenberg block editor on a page or post
- Add Anchor blocks where you want in-page navigation targets
- Edit each anchor label directly in the editor
- Optionally customize the anchor ID from the block sidebar (Settings β Anchor ID)
- Add an Anchors List block (search for "Anchors List" in the Widgets category) to display quick-access links
- On the frontend:
- Each anchor renders as
<span id="your-slug" aria-hidden="true"> - The anchors list renders a linked navigation to
#your-slug
- Each anchor renders as
| Block | Editor behavior |
|---|---|
| Anchor | RichText for the label; slug auto-generated from the title |
| Anchor (sidebar) | TextControl to override the HTML id manually |
| Anchors List | Lists all Anchor blocks on the page; each item is editable via RichText |
Both blocks support theme-level template overrides via get_template_part(). If no theme template is found, the plugin falls back to its default views.
| Block | Default theme slug | Plugin fallback |
|---|---|---|
| Anchor | components/gutenberg/anchor |
views/anchor.php |
| Anchors List | components/gutenberg/anchors-list |
views/anchors-list.php |
Example theme file: components/gutenberg/anchors-list.php
<?php
/**
* @var array $args {
* @type array $block_attributes
* @type string $block_wrapper_attributes
* @type array $anchors
* @type bool $is_preview
* }
*/
$anchors = $args['anchors'] ?? [];
?>
<div <?php echo $args['block_wrapper_attributes']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<!-- Custom theme markup -->
</div>| Filter | Default | Description |
|---|---|---|
blockparty/anchor/classnames |
[] |
Additional CSS class names |
blockparty/anchor/template_slug |
components/gutenberg/anchor |
Theme template slug |
blockparty/anchor/template_name |
'' |
Theme template name |
blockparty/anchor/template_args |
β | Template arguments passed to the view |
| Filter | Default | Description |
|---|---|---|
blockparty/anchors_list/classnames |
['anchor-list'] |
Additional CSS class names |
blockparty/anchors_list/template_slug |
components/gutenberg/anchors-list |
Theme template slug |
blockparty/anchors_list/template_name |
'' |
Theme template name |
blockparty/anchors_list/template_args |
β | Template arguments passed to the view |
Example:
add_filter( 'blockparty/anchors_list/classnames', function ( $classnames, $attributes, $block ) {
$classnames[] = 'my-custom-anchor-list';
return $classnames;
}, 10, 3 );blockparty-anchors/
βββ src/ # Block sources
β βββ anchor/
β β βββ block.json # Anchor block configuration
β β βββ edit.js # Edit component (RichText + inspector)
β β βββ index.js # Entry point
β β βββ editor.scss # Editor styles
β β βββ style.scss # Frontend and editor styles
β βββ anchors-list/
β βββ block.json # Anchors List block configuration
β βββ edit.js # Dynamic list editor component
β βββ index.js # Entry point
β βββ editor.scss # Editor styles
β βββ style.scss # Frontend and editor styles
βββ includes/ # PHP classes
β βββ Anchors.php # Anchor discovery and caching
β βββ BlockRenderer.php # Dynamic block rendering
βββ views/ # Default PHP templates
β βββ anchor.php
β βββ anchors-list.php
βββ build/ # Compiled assets (blocks-manifest.php, etc.)
βββ languages/ # Translation files
βββ .wordpress-org/blueprints/ # WordPress Playground blueprint
βββ blockparty-anchors.php # Main plugin file
βββ composer.json # PHP dependencies
βββ package.json # JavaScript dependencies
# Development with hot reload
npm start
# Production build
npm run build
# JavaScript linter
npm run lint:js
# CSS linter
npm run lint:css
# Code formatting
npm run format
# Generate POT file
npm run make-pot
# Generate JSON translation files
npm run make-json
# Create plugin ZIP archive
npm run plugin-zip
# Start local development environment
npm run env:start
# Stop local development environment
npm run env:stop# Check code with PHP_CodeSniffer
composer cs
# Automatically fix code
composer cb
# Run unit tests
composer phpunitThe project follows WordPress coding standards:
- WPCS (WordPress Coding Standards) for PHP
- ESLint with WordPress rules for JavaScript
- GrumPHP to automate pre-commit checks
The plugin uses @wordpress/env to create a local WordPress development environment:
# Start the environment
npm run env:start
# Access WordPress
# URL: http://localhost:8888
# Default credentials: admin / password
# Stop the environment
npm run env:stopThe project integrates several quality tools:
- PHP_CodeSniffer: PHP coding standards verification
- PHPCompatibility: PHP compatibility verification
- PHP Parallel Lint: PHP syntax error detection
- GrumPHP: Pre-commit checks automation
The plugin is fully internationalized (text domain: blockparty-anchors). Translation files are available in the languages/ folder.
- English (default)
- French (
blockparty-anchors-fr_FR.po)
- Use the
languages/blockparty-anchors.potfile as a base - Create your
.poand.mofiles - Place them in the
languages/folder - Run
npm run make-jsonto generate Jed JSON files for the block editor
Contributions are welcome! To contribute:
- Fork the project
- Create a branch for your feature (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Make sure your code:
- Follows WordPress coding standards
- Passes all quality tests (PHPCS, ESLint)
- Is properly documented
- Includes translations if necessary
This plugin is distributed under the GPL-2.0-or-later license.
Be API Technical Team
- Email: technical@beapi.fr
- Website: https://beapi.fr
- WordPress Block Editor Documentation
- WordPress Coding Standards
- Block API Reference
- Dynamic Blocks (Server-Side Rendering)
See readme.txt for the full version history. Recent highlights:
- 1.0.0
- Initial release with Anchor and Anchors List blocks, dynamic PHP rendering, theme template overrides, editor synchronization, and French translations.
Developed with β€οΈ by Be API