Created
August 14, 2014 14:45
-
-
Save KB1RMA/1c6044d107855a38f51b to your computer and use it in GitHub Desktop.
Very useful to output a category link with just the slug of a category. Saves lots of hardcoded URL's ending up all over a theme that need to be rebuilt when the permalink structure changes/is changed.
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 | |
// Useage: <a href="<?php category_link('prwhiteboard') ?>">PR Whiteboard</a> | |
if (!function_exists('category_link')) { | |
function category_link($slug) { | |
$cat = get_category_by_slug($slug); | |
$id = $cat->term_id; | |
// If the theme implements the relative URL filtering provided by the roots | |
// starter theme, let's filter the output first so everything is squeaky clean | |
if (function_exists('roots_root_relative_url')) { | |
echo roots_root_relative_url(get_category_link($id)); | |
} else { | |
echo get_category_link($id); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment