This is definitely helpful, thank you!
However, I wonder if your [wpv-archive-title] shortcode could be modified to take some arguments? Obviously, you already make calls to existing WordPress functions, so this should not be a problem for you from a development standpoint.
I think that your short code could pretty easily be implemented in much the same way that you have done here, except that you should provide an additional argument, $prefix, which defaults to the empty string. Thus your shortcode could be implemented something like this:
function wpv_archive_title( $prefix = null ) {
// Preserve your current default behavior
if ($prefix == null || strlen($prefix ==0) {
$title = get_the_archive_title();
}
else {
if ( is_category() ) {
$title = $prefix . single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = $prefix . single_tag_title( '', false );
} elseif ( is_author() ) {
$title = $prefix . '<span class="vcard">' . get_the_author() . '</span>';
} elseif ( is_post_type_archive() ) {
$title = $prefix . post_type_archive_title( '', false );
} elseif ( is_tax() ) {
$title = $prefix . single_term_title( '', false );
}
}
return $title;
}
Would you please forward this to the development team as a feature request?
Thank you.
David McLeod
I apologise, but I need more details to this.
Am I correct that you want to output the archive title with Toolset, which will always display "Taxonomy_Name Archives: Term_Name", without the String "Archives:"?
So for example, you want to customize (or remove) "Category" in:
Category Archives: Uncategorized
I have seen others asking to remove the word "archive", and even others to choose to display the Term ID, or slug, instead of its name.
Those are all valid requests.
Would you agree upon:
- provide a method to alter the prefix of the *Category Archives: Uncategorized* string
- provide a method to alter what to output for the Taxonomy (Slug, ID, Name)
- provide a method to alter what to output for the Term (Slug, ID, Name)
- provide method to alter string "Archives:"
When you invoke get_the_archive_title(), you get back something like the following...
"Category: <Some Category>"
"Tag: <Some Tag>"
"Author: <Some Author>"
However, the different method calls in the code above just return the substrings "<Some Category>", "<Some Tag>", "<Some Author>", etc. That is, the same archive title WITHOUT the prefix.
I'm recommending that you modify the [wpv-archive-title] shortcode to make the prefix optional (or to change it to something else. Incorporating the other ideas you list at the bottom of your message suggests to me a shortcode of the following structure:
[wpv-archive-title prefix="Optional Prefix" taxonomy="slug | id | name" term="slug | id | name"]
All options are nullable, defaulting to the current behavior (which ensures that any existing usages of [wpv-archive-title] will still work. The implementation would be something similar to what I've provided above, although you may have additional use-cases to consider.
I hope this answers your question.
David McLeod
Great, thanks.
I have filed it here for the records https://toolset.com/feature-request/extend-the-views-archive-title-shortcode-so-to-customize-the-output/, however likely this system soon changes and the list might disappear, there is hence no hurry in voting it up either.