30.05.2012

In the absence of a get_slug function – here’s a couple of custom functions in WordPress that I have often found as good, useful add-ons to your functions.php file whenever the need to get a tag or page slug arises.

[crayon title=”WordPress Get Slug Functions”]

function mytheme_get_tag_slug($title) {
global $wpdb;
$slug = $wpdb->get_var(“SELECT slug FROM $wpdb->terms WHERE name=’$title'”);
return $slug;
}

function mytheme_get_page_slug($pageID) {
global $wpdb;
$slug = $wpdb->get_var(“SELECT post_name FROM $wpdb->posts WHERE ID=’$pageID'”);
return $slug;
}[/crayon]

Leave a Reply

Your email address will not be published. Required fields are marked *