Forums

[resolved] [Plugin: Simple Taxonomies] Why doesn't yoast_term_title return titles? (7 posts)

  1. sonofbruce
    Member
    Posted 2 years ago #

    I'm using yoast_term_title at the top of term archive pages, and it's less than optimal in the sense that it gives the hypenated slug (albeit with the first letter capitalized) rather than the true title of the term a la single_tag_title on tag archive pages. Is there another template function I should be using instead? (Obviously I am a PHP neophyte, which is why I'm using this plugin in the first place.) FWIW the site is http://movingpoems.com/

  2. satanas147
    Member
    Posted 2 years ago #

    You can edit your simple_taxonomies.php file, around line 336, and add these two functions:

    function get_yoast_term_name() {
    	if ( !is_tax() )
    		return;
    	$term = get_term_by( 'slug', get_query_var('term'), get_query_var('taxonomy') );
    	return $term->name;
    }
    
    function yoast_term_name() {
    	echo get_yoast_term_name();

    Using yoast_term_name() instead of yoast_term_title will solve your issue.

  3. sonofbruce
    Member
    Posted 2 years ago #

    Thank you very much. If it requires that much tweaking of the plugin, though, I'm thinking I might have another go at editing functions.php and dropping "Simple" Taxonomies altogether.

  4. Justin Tadlock
    Member
    Posted 2 years ago #

    I don't see why the plugin would even need this. There really needs to be a single_term_title() template tag in WP.

    Just add this to your template:

    <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name; ?>
  5. donbosco
    Member
    Posted 2 years ago #

    This plugin works great. I am using it to show a tag cloud specific to one category (articles). I have the same issue with the yoast_term_title returning the slug instead of name.

    I tried both of the solutions mentioned above. Santanas147 code broke my site. I added Greenshady's code to my functions.php file in the template directory but when I added a call to single_term_title() in the archives.php file, it returned nothing. Not sure if I added the code to the right place.

    Any ideas?

  6. S.K
    Member
    Posted 2 years ago #

    I used this in the template:

    <?php echo $taxonomy. ':' . $term; ?>

    It produced the desired result. I don't know if I am dyslexic!

    I tried using the function on my template but it returns the title of the current term all right but it is prefixed with a ">". Dunno where from it is picked up though!!

    S.K

  7. donbosco
    Member
    Posted 2 years ago #

    Ok, I realized that Greenshady's code was for the page template and not the functions.php file. Once I plugged it into my page it worked perfectly! Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic