I'm trying to build up a menu of category links for specific categories I'd like to highlight and apply styling/classes to.

I've tried this sort of thing.

<li><a href="<?php get_site_url(); ?>category/Gadgets"> Gadgets</a></li>


 <li><a href="category/Gadgets"> Gadgets</a></li>

It's showing up as sitename/category/category/category/gadgets on the front end.

I can't use <?php wp_list_categories('orderby=name&title_li='); ?> because it's going to spit out all of them and limit the styling I can do on the html.

I just want to link to categories directly, by name, preferably without hard coding in the site name.


4 Answers 4


There is a function called get_category_link() which might be helpful for you. This will be able to generate an appropriate link without having to hard-code it, except for the category name or ID.

Examples from the Wordpress Codex:

    // Get the ID of a given category
    $category_id = get_cat_ID( 'Category Name' );

    // Get the URL of this category
    $category_link = get_category_link( $category_id );

<!-- Print a link to this category -->
<a href="<?php echo esc_url( $category_link ); ?>" title="Category Name">Category Name</a>



Specific to your demand, try this:

<li><a href="<?php echo home_url() ?>/category/Gadgets"> Gadgets</a></li>

use wp_list_categories('include=3,5,9,16');, replace "3,5,9,16" with your category ids ( comma separated

another method

get_category_link( $category_id );

see wordpress codex here

One more method is to create category menu in admin and print it in your theme ( if theme supports menus )


get_site_url() returns a string with the URL, it does not print it. So you may try

<?php echo get_site_url(); ?>

or better:

<?= get_site_url(); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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