#42768 closed enhancement (duplicate)
the_archive_title clutter
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.9.1 |
Component: | Themes | Keywords: | has-patch has-dev-note |
Focuses: | ui, template | Cc: |
Description
This function (and its get_ counterpart) is adding the "Archives:" prefix to the archive title. While the reason for this is understandable, not every site is a news/blog site, and many of us wishes to remove this (as it is clutter for some presentation sites, where we use standard WordPress behavior and custom post types for listing things).
This function is very useful, as it works with any kind of archives. However, the clutter isn't.
It's OK to leave the feature in by default. The only thing that is needed, to add a parameter which we can use to turn it off (using false).
For example:
the_archive_title($before = '', $after = '', $use_title_prefix = true);
Attachments (2)
Change History (12)
#2
in reply to:
↑ 1
@
7 years ago
Replying to Presskopp:
I think this could be filtered like
https://gist.github.com/proweb/f329cde740e0802870871bef830fab50
Yes, that is pretty much the kind of duplicate code I would like to avoid, given how the clutter is being added in get_the_archive_title()
. Calling single_cat_title()
twice to just get the archive title without the clutter. And single_cat_title()
has a somewhat deep call stack on its own. Right now, we are undoing something that has been done 2 ms earlier by rerunning almost the same thing.
I'm not asking to remove these title prefixes. It's just a request to make them optional. Aside of being less work for theme developers, it's also a bit less work for servers to do. Also, my suggestion won't break backwards compatibility either.
#5
@
6 years ago
- Keywords has-patch dev-feedback added; needs-patch removed
Hello everyone.
I tried to create a patch to fix this issue. It would also solve #31237 and #38545.
I've split $title in 2 variables: $prefix and $title. I'v created a new filter "get_the_archive_title_prefix" in order to be able to change the prefix, without changing the whole text.
Developers would be able to:
- remove the prefix
<?php add_filter( 'get_the_archive_title_prefix', __return_empty_string() );
- add for exemple a <span> or a <strong> tag for the prefix
<?php add_filter( 'get_the_archive_title_prefix', sx_archive_prefix ); function sx_archive_prefix( $prefix ){ return '<strong>' . $prefix . '</strong>'; }
This patch should not break backward compatibily : the get_the_archive_title() filter still exists and will still filters all get_the_archive_title() data. Developers would not need to change directly the get_the_archive_title() function in their themes and plugins.
Am I doing it right ?
#6
@
6 years ago
- Keywords needs-patch added; has-patch removed
@Confridin String concatenation like $title = $prefix . $title;
is really bad for translators as they now have no context for how these strings are used. Just think about right-to-left languages as an example.
#7
@
6 years ago
Should I replace
$title = $prefix . $title;
with
$title = sprintf( __( '%1$s%2$s' ), $prefix, $title );
to solve this issue ?
#9
@
5 years ago
- Component changed from General to Themes
- Keywords dev-feedback removed
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
Duplicate of #31237.
I think this could be filtered like
https://gist.github.com/proweb/f329cde740e0802870871bef830fab50