WordPress.org

Ready to get started?Download WordPress

Forums

function equivalent to single_term_title();? (3 posts)

  1. Salum
    Member
    Posted 4 years ago #

    So, I'm doing my custom taxonomy page taxonomy-blog_cats.php and I found myself before an akward question. How do I get to display the name of the taxonomy? I tried using the_title(); - It returns me the name of the first matched post

    I tried single_cat_title(); - returns me nothing

    I tried single_tag_title(); - returns me nothing

    I tried single_post_title(); - same as the_title();

    How do I work around this? thanks

  2. Salum
    Member
    Posted 4 years ago #

    anyone? I still can't figure this out

  3. Mohammad Jangda
    Member
    Posted 3 years ago #

    According to this ticket, that function will be added in 3.1. Until then you can use this (it's just a modification of single_tag_title):

    if( !function_exists( 'single_term_title' ) ) :
    	function single_term_title($prefix = '', $display = true ) {
    		global $wp_query;
    
    		if ( !is_tax() )
    			return;  
    
    		$term = $wp_query->get_queried_object();
    
    		if ( ! $term )
    			return;
    
    	    $my_term_name = apply_filters('single_tag_title', $term->name);
    
    	    if ( !empty($my_term_name) ) {
    			if ( $display )
    				echo $prefix . $my_term_name;
    			else
    				return $my_term_name;
    		}
    	}
    endif;

Topic Closed

This topic has been closed to new replies.

About this Topic