How can we add # before each tag with both the_tags( ) and wp_tag_cloud( )?

  • Note: We need this, because without a hash a tag is worthless.. :) Jul 21, 2015 at 15:59

3 Answers 3


Another very simple solution is to put this in your css file :

.tagcloud a:before {
  content: "#";
  font-color: #000;

You will have to use your own custom function, the_tags( ) doesn't allow you to do that. You could create a function like this, using get_the_tags, and format your html as you prefer :

function hashtags() {
    $posttags = get_the_tags();
    if ($posttags) {
        foreach($posttags as $tag) {
            echo '<a href="' . get_tag_link($tag->term_id) . '">#' . $tag->name . '</a> '; 

You can do it with applying filter. Example:

add_filter( 'the_tags', 'add_hash_to_tags', 10, 2 );
function add_hash_to_tags($tag_list, $before) {
    return str_replace('rel="tag">', 'rel="tag">#', $tag_list);
New contributor
Alexandr Prylipko is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.