[wp-trac] [WordPress Trac] #21995: (get/the)_archive_title and (get/the)_archive_description functions

WordPress Trac noreply at wordpress.org
Wed Nov 5 17:27:16 UTC 2014


#21995: (get/the)_archive_title and (get/the)_archive_description functions
---------------------------------------------+--------------------------
 Reporter:  thomask                          |       Owner:  johnbillion
     Type:  feature request                  |      Status:  reopened
 Priority:  normal                           |   Milestone:  4.1
Component:  Themes                           |     Version:  trunk
 Severity:  normal                           |  Resolution:
 Keywords:  has-patch twenty-fifteen commit  |     Focuses:  template
---------------------------------------------+--------------------------

Comment (by McGuive7):

 Thanks for the response Frank, very helpful. And I totally agree in
 regards to translation - I see all the important pieces in place already.
 My question is more around filtering the prefix specifically. At present,
 for someone to filter just the prefix, they actually have to filter the
 entire title, which requires essentially duplicating whatever function is
 being used to generate the non-prefix part of the title. Not super hard,
 but also not my favorite choice for two reasons:

 1. It requires users to dig into core code (or the codex) to reproduce
 functionality when really they might just want to remove the word
 "Archives:".

 2. The present method smushes together what I see as two separate pieces
 of content: a prefix and an actual title. To me, the prefix and the title
 in this situation are much like a label and an input in a form. Or an icon
 and a link that sit next to each other. One is primary and one is
 secondary. You could also say one is more ornamental, and more is more
 fundamental. Most coding and design folks agree that the two should be
 separated, right? Same seems true in this case.

 So, what do I propose? Well here's a look - would love to know why this
 would or wouldn't make sense:

 Old code style (consolidated for example):

 {{{
 if ( is_category() ) {
         $title = sprintf( __( 'Category: %s' ), single_cat_title( '',
 false ) );
 }

 return apply_filters( 'get_the_archive_title', $title );
 }}}

 Proposed update:
 {{{
 $prefix = '';

 if ( is_category() ) {
         $prefix = __( 'Category:' );
         $title = single_cat_title( '', false );
 }

 // Add blank space after prefix as needed
 $prefix = $prefix ? $prefix . ' ' : '';

 // Filter prefix
 $prefix = apply_filters( 'get_the_archive_prefix', $prefix );

 // Output prefix and title
 return $prefix . apply_filters( 'get_the_archive_title', $title );
 }}}

 You make mention of needing an array of prefix values for filtering, but
 this method doesn't seem to require that - unless I'm missing something.
 Sure it's a bit of extra code, but it adds a filter that I know I've
 wished was there a number of times. It's so much handier to just filter
 the prefix than have to override the entire output, right?

 As for what you said about Underscores being reviewed regularly by
 experienced folks - I fully agree. AND, isn't that what we're doing right
 now? I think it's conversations like these that contribute to some of
 Underscores continual improvements.

 Thanks! Would love to hear more on why this is/isn't a good solution.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/21995#comment:46>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list