Created
November 27, 2022 21:45
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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