#31237 closed enhancement (fixed)
improve get_the_archive_title() with new filter
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.5 | Priority: | normal |
Severity: | normal | Version: | 4.1 |
Component: | Themes | Keywords: | has-patch has-dev-note |
Focuses: | template | Cc: |
Description
The new get_the_archive_title() function introduces in wordpress 4.1 is very handy but it's very basic.
In some themes we prefer to hide the page prefix (i.e. Category, Tag, ect.).
I was thinking of a boolean parameter/filter in the function to show/hide the prefix.
if true, use:
__( 'Category: %s' )
else, use:
__( '%s' )
Attachments (3)
Change History (20)
#2
in reply to:
↑ 1
@
10 years ago
With the current get_the_archive_title
filter, you have to write a very long code to filter each and every page type to remove the prefix. It's not developer friendly.
And as a developer, I prefer to write my own function to replace get_the_archive_title()
than using this filter. Writing my own function is faster and easier than filtering the current function.
On the other hand, a boolean filter is simpler, faster and developer friendly.
For example, using this simple snippet in your functions.php
file:
// Remove archive title prefix add_filter( 'archive_title_prefix', '__return_false' );
Theme authors can remove the title prefix, and another developer can create child-theme to add the prefix back (with return true). As i said, boolean filters are simpler and developers friendly.
#3
@
9 years ago
Rather than add a filter I would like to see a span wrapped around the prefix. Then users can optionally hide the prefix with CSS, or I can hide the prefix in the theme.
I sell premium themes on wordpress.com and hiding the prefix is a very frequent request.
#4
follow-up:
↓ 5
@
9 years ago
@BinaryMoon, I like your css approach but I think a boolean filter is simpler and search-engine-friendly.
#5
in reply to:
↑ 4
;
follow-up:
↓ 6
@
9 years ago
Replying to ramiy:
@BinaryMoon, I like your css approach but I think a boolean filter is simpler and search-engine-friendly.
I'd disagree that introducing more code is simpler. I think a span is a very simple solution that means we can all get the functionality we want. It also means that all users will get the functionality added to their sites without a theme update.
My concern is that I have users who are happy with it as is, and a small handful of users who want it changed. So I don't want to remove it for everyone as that will mean I am changing their website. I also don't want to introduce yet another option in the theme. If a span is added then those who really don't want it can use css to hide it. Everyone else can continue as is.
#6
in reply to:
↑ 5
@
9 years ago
Replying to BinaryMoon:
I'd disagree that introducing more code is simpler. I think a span is a very simple solution that means we can all get the functionality we want. It also means that all users will get the functionality added to their sites without a theme update.
The css approach is not semantic and not accessible. With css span you don't remove the prefix text you just hide it. The search engine still see the text, the blind person still hear the text with his device. I think we should totally remove it. We don't need to echo the prefix text if it's not being presented.
My concern is that I have users who are happy with it as is, and a small handful of users who want it changed. So I don't want to remove it for everyone as that will mean I am changing their website.
The new filter don't remove the prefix text for everyone, it only adds the ability not to show the prefix to those how chose to use the filter.
I also don't want to introduce yet another option in the theme. If a span is added then those who really don't want it can use css to hide it. Everyone else can continue as is.
No mater what approach we chose, you don't have to update your theme. users can remove the prefix text with css (in style.css) or with the the filter (in functions.php).
#7
@
9 years ago
I'm coming at this from the point of view of a theme developer who sells themes. My users do not (generally) modify themes. Many of the themes I sell are on wordpress.com. As such - if I chose to use the toggle - it will affect everyone.
I chose the span entirely because it's not semantic. I didn't want to add semantic meaning unnecessarily. It doesn't have to be a span.
As for accessibility - I would argue that hiding the span with css is more accessible since it gives context to what is normally the page title. If you hide the prefix with css then users with screenreaders will more easily be able to tell what page they are on. I assume this is the reason for the prefix in the first place. Not printing it to the page at all removes this context.
Note - I don't use screen readers so don't know if there's other ways of getting the same info :)
How would existing users be able to hide the prefix with css if there's no span (or other element) to target the prefix?
#8
@
9 years ago
- Keywords has-patch added
The patch adds a filter that allows you to show/hide the archive page prefix.
By default it shows the prefix. for backwards-compatibility.
Use this filter to hide the prefix:
// Remove archive title prefix add_filter( 'archive_title_prefix', '__return_false' );
This ticket was mentioned in Slack in #core by ramiy. View the logs.
9 years ago
This ticket was mentioned in Slack in #themereview by joyously. View the logs.
7 years ago
#16
@
5 years ago
- Owner set to ocean90
- Resolution set to fixed
- Status changed from new to closed
In 48294:
Why not just use the
get_the_archive_title
filter as it's already there and works perfectly well?