admin管理员组

文章数量:1277303

I am using the snippet below to add the category or tag title to their respective archive page title. While the category title is working as expected, the portion that is supposed to target the tag archive pages (e.g. example/events/tag/road-race/) is not having any effect on those page titles.

I tried removing tribe_is_upcoming() && so that it would only require that the query is for the post_tag taxonomy, but that isn't working either. I also tried specifying the post_tag conditional as is_tag(post_tag) and that doesn't have any effect.

I inspected the tag pages with the Query Monitor plugin and the following conditionals are true:
is_archive()
is_post_type_archive()
is_ssl()
is_tag()

The only difference in the tag conditionals vs category conditionals is that the category pages have is_tax() as being true, while the tag pages have is_tag() as true.

Am I using the wrong function (single_tag_title) or missing something else with the conditionals?

function filter_events_title( $title ) {
  // Single venues
  if ( tribe_is_venue() ) {
    //$title = 'Single venue page';
    $title = sprintf('%1$s Running Race Calendar', get_the_title() );
 );
  }
  // List view category page: upcoming events
  elseif ( tribe_is_upcoming() && is_tax(tribe_events_cat) ) {
    //$title = 'Category Running Race Calendar';
    $title = sprintf('%1$s Race Calendar', single_cat_title( '', false ) );
  }
  // List view category page: past events
  elseif ( tribe_is_past() && is_tax(tribe_events_cat) ) {
    $title = sprintf('%1$s Race Calendar', single_cat_title( '', false ) );
  }
  // List view tag page: upcoming events
  elseif ( tribe_is_upcoming() && is_tag() ) {
     $title = sprintf('%1$s Race Calendar', single_tag_title( '', false ) );
  }
  // List view tag page: past events
  elseif ( tribe_is_past() && is_tag() ) {
    $title = sprintf('%1$s Race Calendar', single_tag_title( '', false ) );
  }
   
  return $title;
}
add_filter( 'tribe_events_title_tag', 'filter_events_title' );

I am using the snippet below to add the category or tag title to their respective archive page title. While the category title is working as expected, the portion that is supposed to target the tag archive pages (e.g. example/events/tag/road-race/) is not having any effect on those page titles.

I tried removing tribe_is_upcoming() && so that it would only require that the query is for the post_tag taxonomy, but that isn't working either. I also tried specifying the post_tag conditional as is_tag(post_tag) and that doesn't have any effect.

I inspected the tag pages with the Query Monitor plugin and the following conditionals are true:
is_archive()
is_post_type_archive()
is_ssl()
is_tag()

The only difference in the tag conditionals vs category conditionals is that the category pages have is_tax() as being true, while the tag pages have is_tag() as true.

Am I using the wrong function (single_tag_title) or missing something else with the conditionals?

function filter_events_title( $title ) {
  // Single venues
  if ( tribe_is_venue() ) {
    //$title = 'Single venue page';
    $title = sprintf('%1$s Running Race Calendar', get_the_title() );
 );
  }
  // List view category page: upcoming events
  elseif ( tribe_is_upcoming() && is_tax(tribe_events_cat) ) {
    //$title = 'Category Running Race Calendar';
    $title = sprintf('%1$s Race Calendar', single_cat_title( '', false ) );
  }
  // List view category page: past events
  elseif ( tribe_is_past() && is_tax(tribe_events_cat) ) {
    $title = sprintf('%1$s Race Calendar', single_cat_title( '', false ) );
  }
  // List view tag page: upcoming events
  elseif ( tribe_is_upcoming() && is_tag() ) {
     $title = sprintf('%1$s Race Calendar', single_tag_title( '', false ) );
  }
  // List view tag page: past events
  elseif ( tribe_is_past() && is_tag() ) {
    $title = sprintf('%1$s Race Calendar', single_tag_title( '', false ) );
  }
   
  return $title;
}
add_filter( 'tribe_events_title_tag', 'filter_events_title' );
Share Improve this question asked Oct 1, 2021 at 21:06 irishrunner16irishrunner16 1071 gold badge1 silver badge8 bronze badges 2
  • 2 Is this your actual code? because you have a rogue ); in the first clause, and if tribe_events_cat etc are meant to be strings, they should be quoted. – vancoder Commented Oct 1, 2021 at 21:34
  • 1 Does the parsing even get as far as the is_tag() conditions? Or does one of your other if clauses return true before it gets there? – vancoder Commented Oct 1, 2021 at 21:38
Add a comment  | 

1 Answer 1

Reset to default 0

I found my error. I had elseif ( tribe_is_upcoming() && ! is_tax() ) as a previous conditional, so that was getting applied to the tag pages before it got to the is_tag() conditions. Correcting this to elseif ( tribe_is_upcoming() && ! is_tax() && ! is_tag() ) allowed it to get to the is_tag() conditions.

本文标签: phpTag title not being returned in page title of tag archives