How to enable automatic anchor text generation for headings in WordPress
Do you want to enable automatic anchor text generation for headings in your WordPress site?
If yes then in this tutorial we have shared the step by step process using which you can do this easily.
Automatic anchor text generation is a feature that was first released in WordPress 5.9.
However, due to some issues it was rolled back.
This feature has been re-released as an opt-in in WordPress 6.0 which means it comes disable by default.
And to use it you will have to activate it.
Note- This feature is still under development and activating it can cause issues in some cases. We will be consistently updating tutorial as and when changes are released. Until then we recommend you try this feature on a local environment or take a backup if using on a live site.
Taking this into consideration, when you will activate this feature, it will instantly and automatically generate anchors for all headings on pages and posts.
Be it H1 or H6.
Once these anchors are created, you will find them under the Advanced tab of the Heading block in HTML anchor.
In case you are wondering if you will be able to edit these anchors then the answer is YES.
However, you won’t be able to remove it completely.
It is important to know that this is a very helpful feature as you can use it to create a table of contents on pages and posts.
Also, often these anchors are fetched by search engines which helps boost visibility of the page.
Keeping this in mind, in this tutorial we have shared the step by step process on how can you enable automatic anchor text generation for headings in WordPress.
enable automatic anchor text generation for headings
Before we dive into this tutorial, it is important to know that as this feature is under development there is no plugin available that you can use to activate it.
This means you will have to use a code snippet for enabling automatic anchor text generation for headings.
In this step by step guide we have shared 2 code snippets and you can use any.
Also, we have tested these with several popular themes Kadence, Hello, Astra, GeneratePress and more.
Below are the topic covered
Login to WordPress admin
To enable automatic anchor text generation for headings, the first step is to login to your WordPress admin.
For this you will have to visit https://your-site.com/wp-admin and it will take you to the login page.
Note- Replace your-site.com with your domain name in the above URL.
Here you will have to enter your credentials and click Log In.
Visit Theme File Editor
One your are in your WordPress dashboard, the next step is to head over to the theme file editor.
- Classic theme user (Customizer based)
If you are a classic or a customizer based theme user then you will have to navigate to Appearance in your WordPress dashboard sidebar and click Theme File Editor.
- Block theme users (Site Editor based)
In case you are using a block theme then you will find the Theme File Editor under Tools in your WordPress dashboard sidebar.
Open functions.php
Once you are in the theme file editor, the next step is to find the functions.php in the list of theme files.
On finding, you need to click it to open and it will show you the code. See the below screenshot for ref.
Add code snippet to Generate Anchor Text for Headings Automatically
Now that you have the funtions.php file open, in the next step you need to scroll down to the bottom and add any of the below mentioned code snippets
- Code snippet 1
add_filter(
'block_editor_settings_all',
static function( $settings ) {
$settings['generateAnchors'] = true;
return $settings;
}
);
- Code snippet 2
add_filter( 'block_editor_settings_all', function( $editor_settings, $editor_context ) {
$editor_settings['generateAnchors'] = true;
return $editor_settings;
}, 10, 2 );
After you are done adding the code, click Update File to save changes.
Check if anchors are automatically generated for headings
To check if automatic anchor text generation for headings is enabled, you need to add a new post or a page.
In the next step you need to add Headings block and type in something and you will notice it will create an anchor for this heading automatically.
- List View
- Advanced Tab
And that’s it you have successfully activated automatic anchor text generation for headings in WordPress.
Having said that,
I hope you will find this tutorial helpful and are able to enable automatic anchor text generation for headings in WordPress.
In case you have any queries feel free to get in touch.
To stay up to date with our content we recommend you subscribe to our YouTube channel and email list.
Also, don’t forget to join our Facebook group.