php - How to make function appear in sentence?

I have a function to show theme details and want to put it in a sentence.Like: The "theme" developed by "

I have a function to show theme details and want to put it in a sentence. Like: The "theme" developed by "author". And it will contain links.

I tried printf, did get the correct result.

    function logbook_info() {
    $theme_logbook = wp_get_theme();
    echo esc_html( $theme_logbook->get( 'TextDomain' ) );
    echo esc_html( $theme_logbook->get( 'ThemeURI' ) );
    echo esc_html( $theme_logbook->get( 'AuthorURI' ) );
}

add_action( 'logbookinfo', 'logbook_info' );

I have a function to show theme details and want to put it in a sentence. Like: The "theme" developed by "author". And it will contain links.

I tried printf, did get the correct result.

    function logbook_info() {
    $theme_logbook = wp_get_theme();
    echo esc_html( $theme_logbook->get( 'TextDomain' ) );
    echo esc_html( $theme_logbook->get( 'ThemeURI' ) );
    echo esc_html( $theme_logbook->get( 'AuthorURI' ) );
}

add_action( 'logbookinfo', 'logbook_info' );
Share Improve this question edited Dec 31, 2019 at 19:22 butlerblog 5,1213 gold badges28 silver badges44 bronze badges asked Dec 31, 2019 at 10:55 webfuelcodewebfuelcode 212 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

You can use below code to display theme detail sentence. I have use wp_footer action,You can change hook as per your requirement.

function logbook_info() {
    $theme_logbook = wp_get_theme();
    $theme_name = esc_html( $theme_logbook->get( 'Name' ) );
    $theme_uri = esc_html( $theme_logbook->get( 'ThemeURI' ) );
    $theme_author = esc_html( $theme_logbook->get( 'Author' ) );
    $theme_author_uri = esc_html( $theme_logbook->get( 'AuthorURI' ) );

    $theme_html = '<a href="'.$theme_uri.'">'.$theme_name.'</a>';
    $author_html = '<a href="'.$theme_author_uri.'">'.$theme_author.'</a>';

    echo "The ".$theme_html." developed by ".$author_html;
}
add_action( 'wp_footer', 'logbook_info' );

It will add theme detail in footer : https://prnt.sc/qhva3o

function logbook_info() {
    $theme_logbook = wp_get_theme();
    echo 'The'.esc_html( $theme_logbook->get( 'TextDomain' ) ). 'Developed by '.
    esc_html( $theme_logbook->get( 'AuthorURI' ) );
}

add_action( 'logbookinfo', 'logbook_info' );

Try this.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744868864a4598138.html

相关推荐

  • php - How to make function appear in sentence?

    I have a function to show theme details and want to put it in a sentence.Like: The "theme" developed by "

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信