Skip to content

Instantly share code, notes, and snippets.

@iansvo
Created November 27, 2022 21:45
Show Gist options
  • Save iansvo/9a46d6aaf8d62de13e2b309a429d37cd to your computer and use it in GitHub Desktop.
Save iansvo/9a46d6aaf8d62de13e2b309a429d37cd to your computer and use it in GitHub Desktop.
Add's a hash (#) to the front of a tag on the frontend of WordPress
<?php
add_filter('get_term', function ($term, $taxonomy) {
// Bail if we're in the admin
if( is_admin() ) {
return $term;
}
$already_modified = strpos( $term->name, '#' ) === 0;
if ( $taxonomy === 'post_tag' && ! $already_modified ) {
$term->name = '#' . $term->name;
}
return $term;
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment