Site icon Hip-Hop Website Design and Development

How to Alter Node URL Alias Based on Taxonomy Term in Cheap WordPress maintenance support plans 8

Recently I had to generate term-specific aliases (aliases that are different from the default alias pattern set for Article entities). This is how to do it:

1. Enable the Pathauto plugin
2. Set the default URL alias pattern for your content type in order to fire the hook
3. Implement hook_pathauto_alias_alter() in your .plugin file.

Example plugin structure:

myplugin/
– myplugin.info.yml
– myplugin.plugin
– src/
– ArticlePathAlias.php

I like to keep .plugin clean and simple and because of that I store the main logic in src/ArticlePathAlias.php file.

The myplugin.info.yml this is just a regular .info file.

4. Add the following to your myplugin.plugin file:
Source: New feed