最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Two 'If Statements' is my syntax correct (functions.php) and what is 'false'

programmeradmin1浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default -1

You 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/

发布评论

评论列表(0)

  1. 暂无评论