[wp-trac] [WordPress Trac] #38545: Add span element to get_the_archive_title()
WordPress Trac
noreply at wordpress.org
Fri Sep 8 22:54:22 UTC 2017
#38545: Add span element to get_the_archive_title()
-------------------------------------+------------------------------
Reporter: Kaira | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 4.6.1
Severity: normal | Resolution:
Keywords: has-patch needs-refresh | Focuses:
-------------------------------------+------------------------------
Comment (by javorszky):
Hello,
Great idea for improving it! :)
Few observations:
if `span_class` is empty, the output will have a trailing space before the
closing `>` of the opening `<span>`. So it's be `<span >Category:</span>
foo`. That could be solved by adding the space here (notice the space
before "class"):
{{{
if ( ! '' == $span_class ) {
$span_class = sprintf( ' class="%s"', sanitize_html_class(
$span_class ) );
}
}}}
This currently doesn't work with RTL languages. For that to work, you'd
have to do
{{{
/* translators: Archive title format. 1: span classes, 2: archive type
name, 3: archive term */
$format = _x( '<span%1$s>%2$s</span>%3$s', 'archive title format' );`
$title = sprintf( $format, $span_class, $type, $name );
}}}
That way any RTL language could have a translation that would essentially
be
{{{
$format = '%3$s<span%1$s>%2$s</span>
}}}
after translation and the `sprintf` would still work.
From a technical point of view, if you accept span class as an array, or
break it up by spaces, then you can add the author's `vcard` classname to
the array. So it'd be
{{{
if ( ! '' == $span_class && is_string( $span_class ) ) {
$span_class = explode( ' ', $span_class );
$span_class = sprintf( 'class="%s"', sanitize_html_class(
$span_class ) );
}
// then later
} elseif ( is_author() ) {
/* translators: Author archive title. %s: Author name */
$type = __( 'Author: ' );
$span_class[] = 'vcard';
$name = get_the_author();
} elseif ( is_year() ) {
// and finally
$title = sprintf( $format,' classes="' . implode( ' ', $span_class ) .
'"', $type, $name );
}}}
And that's about it from me for now. Let me know what you think.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38545#comment:24>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list