This members-only tutorial provides the steps to define a custom function in WordPress that outputs categories of the current post that are not children of other categories - separated by commas.

Ex.:

For a post that belong to these categories:

the function will output:

Notice how "Child Category 1" does not get included since it is a child category.

If using Oxygen, add a text component like Text or Heading. Double click the text, click Insert Data button in the top toolbar, then PHP Function Return value and put in the Function Name, wpdd_post_categories_toplevel and then click INSERT.

Step 1

Install and activate Code Snippets plugin.

Go to Snippets > Add New.

Title: [Function] Output comma-separated top-level categories of the current post

Code:

This is a premium members-only content.

To view the rest of the content, please sign up for membership ($37/month or $399 one-time).

Already a member? Log in below or here.

Need help implementing a tutorial in your site or want to hire me for custom work?

HIRE ME

Find the article helpful and wish to donate?

DONATE
magnifiercross
>
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram
%d bloggers like this: