Home > Blogs, Bookmarks, PhP, Tech, Wordpress > single_cat_title deprecated in wordpress 2.7

single_cat_title deprecated in wordpress 2.7

December 15th, 2008 Leave a comment Go to comments

Function single_cat_title() displays or returns the category title for the current page. For pages displaying WordPress tags rather than categories (”/tag/geek”) the name of the tag is displayed instead of the category.
Usage (only outside The Loop):

<?php single_cat_title('prefix', 'display'); ?>

Next example assigns the current category title to the variable $current_category for use in code:

<?php $current_category = single_cat_title("", false); ?>

for wordpress 2.7 or newer version use get_the_category function instead of single_cat_title. get_the_category() returns an array of objects, one object for each category assigned to the post.

single_cat_title “simulation” Usage (outside the loop ; single.php):

<?php
$category = get_the_category();
$current_category = $category[0]->cat_name;
?>
  1. No comments yet.
  1. No trackbacks yet.
GoCache - ByREV-Cache v1.0 - live served in : 0.321389 sec (gzip)