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

php - How to make function appear in sentence?

programmeradmin4浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论