Problem:
How can you display the name of the current term on a taxonomy archive page outside of the loop.
Solution:
It is currently not possible, though is an obvious omission, and the feature should be added soon.
In the meantime you can register a custom shortcode to output the term, which will output the name by default but when using the field argument can optionally output and of the name, slug, the description, count, or the taxonomy itself.
/* * Output taxonomy fields on a taxonomy archive * * attribute 'field' : name | slug | taxonomy | description | count */ add_shortcode( 'taxonomy', function( $atts = [] ){ // default to taxonomy name $atts = shortcode_atts( [ 'field' => 'name' ], $atts ); $output = ""; global $wp_query; $tax = $wp_query->get_queried_object(); $field = $atts['field']; $output = $tax->$field; return $output; });
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+00:00)
This topic contains 2 replies, has 2 voices.
Last updated by 6 years, 4 months ago.
Assisted by: Nigel.