the Blog

Tutorials | Web Design | WordPress

How to Display Post Categories with a Pipe Instead of a Comma in WordPress

Today, I’m sharing How to Display Post Categories with a Pipe Instead of a Comma in WordPress. Have you ever looked at your WordPress post meta and thought, “Wow, this comma-separated list is super laaaame”? Same. ????

That’s why today we’re spicing things up – literally – with a pipe (|) separator. It’s cleaner, it’s trendier, and let’s be honest: it just looks cooler.

Why Customize Category Output?

By default, WordPress outputs post categories with commas separating them. That’s fine… but sometimes you want a little more control over styling or format – especially if you’re going for a clean, minimal look.

Using a | separator makes your category list more modern and visually scannable. Plus, it’s a fun way to stand out from the sea of default WordPress setups.

How to Display Post Categories with a Pipe Instead of a Comma in WordPress

In this quick tutorial, I’ll show you how to ditch the default boring commas and display your post categories using a vertical bar instead. Like | This .. And bonus: we’re doing it with a custom shortcode you can use anywhere on your site. End-Result example:

How to Display Post Categories with a Pipe Instead of a Comma in WordPress
How to Display Post Categories with a Pipe Instead of a Comma in WordPress

Step-by-Step: Display Categories with a Pipe Separator

Here’s exactly how to make it happen.

????️ Step 1: Add This Code to Your functions.php 

You can pop this into your child theme’s functions.php file, or use a code snippets plugin (Code Snippets is awesome for those of you not comfy editing core files).

// Create a shortcode to display post categories with a pipe separator
function display_post_categories() {
    $categories = get_the_category();
    
    if ($categories) {
        $output = '<div class="post-categories">';
        $category_links = array();

        foreach ($categories as $category) {
            $category_links[] = '<a href="' . esc_url(get_category_link($category->term_id)) . '">' . esc_html($category->name) . '</a>';
        }

        $output .= implode(' | ', $category_links); // Separate with a pipe
        $output .= '</div>';

        return $output;
    }

    return '';
}

// Register the shortcode
add_shortcode('post_categories', 'display_post_categories');

???? What This Code Does

  • Loops through your post categories
  • Creates individual category archive links
  • Combines them using implode() with a pipe (|) as the separator
  • Returns a simple <div> you can style however you like

???? How to Use It

Once your code is added and saved, use the shortcode below anywhere inside your posts, pages, or even theme templates if you’re fancy like that. Simply remove the backticks (had to add those so the code didn’t output MY categories since I’ve used this trick myself 😉 the highlighted portion seen here is what you want:

```
[post_categories]
```

Example Output:

Filed in: <a href="/category/seo">SEO</a> | <a href="/category/wordpress">WordPress</a> | <a href="/category/tutorials">Tutorials</a>


Now that’s some sexy category output. ???? Wow, I am such a nerd.

???? Optional: Add Some CSS Flair

Want to jazz up the appearance even more? Add this to your theme’s CSS file or the WordPress Customizer under Appearance > Customize > Additional CSS:

.post-categories {
    font-style: italic;
    font-size: 14px;
    color: #666;
}
.post-categories a {
    color: #0073aa;
    text-decoration: none;
}
.post-categories a:hover {
    text-decoration: underline;
}

???? Final Thoughts

This little tweak might seem minor, but trust me – when it comes to standing out online, the details matter. Especially in a sea of cookie-cutter blogs and default themes, anything that helps you build a unique vibe is a win.

If you found this tutorial helpful, share it with a fellow WordPress nerd (or tweet me and say hi ????). Wait is it still “tweet me” or do we say “x me” I’m so confused. Anyway, I’m always geeking out on little tricks like this and love to connect with my fellow nerds on social.

P.S. Want more WordPress tips with personality? Sign up for my newsletter below and I’ll send them straight to your inbox—no fluff, no spam, just real talk and real help. ????

P.S.S. Excited about the possibility of even more fun little details to set your website apart? Holler at me, and we can talk custom website design!

Written By: Lindsey Riel

get the newsletter

Subscribe for more pro tips!