The following code works great.
I would just like to know if it is correct to have two 'If' Statements like I have done?
(The purpose of this snippet is to replace the generic "Category, Tag" and replace with custom text).
add_filter( 'get_the_archive_title', 'my_theme_archive_title' );
/**
* Remove archive labels.
*
* @param string $title Current archive title to be displayed.
* @return string Modified archive title to be displayed.
*/
function my_theme_archive_title( $title ) {
if ( is_tax('us_state') ) {
$title = single_term_title( 'Conferences In ', false );
}
if ( is_tax('country') ) {
$title = single_term_title( 'CConferences In ', false );
}
return $title;
}
Also - what is the false statement at the end for? Is it stating whether JQuery needs to be loaded?
Thanks for all feedback - I just want to make sure I am doing it correctly.
The following code works great.
I would just like to know if it is correct to have two 'If' Statements like I have done?
(The purpose of this snippet is to replace the generic "Category, Tag" and replace with custom text).
add_filter( 'get_the_archive_title', 'my_theme_archive_title' );
/**
* Remove archive labels.
*
* @param string $title Current archive title to be displayed.
* @return string Modified archive title to be displayed.
*/
function my_theme_archive_title( $title ) {
if ( is_tax('us_state') ) {
$title = single_term_title( 'Conferences In ', false );
}
if ( is_tax('country') ) {
$title = single_term_title( 'CConferences In ', false );
}
return $title;
}
Also - what is the false statement at the end for? Is it stating whether JQuery needs to be loaded?
Thanks for all feedback - I just want to make sure I am doing it correctly.
Share Improve this question asked May 5, 2019 at 23:07 HenryHenry 9831 gold badge8 silver badges31 bronze badges1 Answer
Reset to default -1You should use elseif for the second if statement:
$title1 = single_term_title( 'Conferences In ', false );
$title2 = single_term_title( 'CConferences In ', false );
add_filter( 'get_the_archive_title', 'my_theme_archive_title' );
function my_theme_archive_title( $title ) {
if ( is_tax('us_state') ) {
$title1;
}
elseif ( is_tax('country') ) {
$title2;
}
else {
return $title;
}
}
You can read here about true/false https://developer.wordpress/reference/functions/single_term_title/