Changing Archive Page "Posts Tagged %s"

Hi there,

I have a situation where I want to change the text of archive pages for tags. Is there a better way to do this than editing the classes/class-fl-theme.php file directly? I found the relevant code on lines 850-898 of that file:

	/**
	 * Renders the content header for post archives.
	 *
	 * @since 1.0
	 * @return void
	 */
	static public function archive_page_header()
	{
		// Category
		if ( is_category() ) {
			$page_title = single_cat_title( '', false );
		}
		// Tag
		else if ( is_tag() ) {
			$page_title = sprintf( _x( 'Posts Tagged ‘%s’', 'Archive title: tag.', 'fl-automator' ), single_tag_title( '', false ) );
		}
		// Day
		else if ( is_day() ) {
			$page_title = sprintf( _x( 'Archive for %s', 'Archive title: day.', 'fl-automator' ), get_the_date() );
		}
		// Month
		else if ( is_month() ) {
			$page_title = sprintf( _x( 'Archive for %s', 'Archive title: month.', 'fl-automator' ), single_month_title( ' ', false ) );
		}
		// Year
		else if ( is_year() ) {
			$page_title = sprintf( _x( 'Archive for %s', 'Archive title: year.', 'fl-automator' ), get_the_time( 'Y' ) );
		}
		// Author
		else if ( is_author() ) {
			$page_title = sprintf( _x( 'Posts by %s', 'Archive title: author.', 'fl-automator' ), get_the_author() );
		}
		// Search
		else if ( is_search() ) {
			$page_title = sprintf( _x( 'Search results for: %s', 'Search results title.', 'fl-automator' ), get_search_query() );
		}
		// Paged
		else if ( isset( $_GET['paged'] ) && ! empty( $_GET['paged'] ) ) {
			$page_title = _x( 'Archives', 'Archive title: paged archive.', 'fl-automator' );
		}
		// Index
		else {
			$page_title = '';
		}

		if(!empty($page_title)) {
			include locate_template('includes/archive-header.php');
		}
	}

I want to change the way the headings read for tag archives to read something like “Matched Tags: %s”

Hope that makes sense! I didn’t know if there was a better way to do this in the functions file of my child theme rather than editing the parent theme directly.

Thanks!

Hi Cody,

I am not sure if you can filter this via your child themes functions.php file or not. So I am going to speak to our developers and see if this is possible or not.

Alternatively, you could try creating a directory called classes in your child theme, copy the class-fl-theme.php file and place it into that folder in your child theme. Then make your changes.

Thanks,
Danny

Hi Danny,

Thanks for checking with the developers. I’m looking forward to a response.

I tried the method you mentioned (creating a directory called classes and copying the class-fl-theme.php file over to make my changes. When I did that and made the changes required, nothing happened. I wonder if the parent theme still overrides that file in this instance.

I’ll try it again, but I’d still love a way to do it from my functions file as you noted.

Thanks!

Hey Cody,

One easy way around this would be to translate the text. Try adding the code below to your functions.php file and let us know how it goes!

// Translate the Header on the tag archive page
function my_text_with_context_translations( $translated, $text, $context, $domain ) {
  if ( 'fl-automator' == $domain ) {
    if ( 'Posts Tagged ‘%s’' == $text && 'Archive title: tag.' == $context ) {
      $translated = 'Matched tags: ‘%s’';
    }
  }
  return $translated;
}
add_filter( 'gettext_with_context', 'my_text_with_context_translations', 10, 4 );

Ben

Hey Ben,

That works. Is there any plan to include the ability to edit archives or other templates with BB?

Most themes I’ve worked on have included just an archive.php file that you could copy over to the child theme and freely edit. This seems strange to me…but no biggie.

Thanks again!

Hi Cody,

The developers are aware of this and archives etc. Are on the our road map, you can see this by visiting our Trello page - https://trello.com/b/pqdibDqC/beaver-builder-roadmap

Thanks,
Danny