在 sprintf 中添加 html

我有一些代码


'next_text' => sprintf( esc_html__( '%s', 'mytheme' ), '%title' ),

我需要在其中添加 html。基本上我想补充


<span>Previous article</span>

在标题之前。我怎样才能做到这一点?


编辑:完整的功能是


function mytheme_single_post_navigation() {

if ( ! is_singular( 'post' ) ) {

    return;

}


if ( ! intval( mytheme_get_theme_mod( 'blog_single_navigation' ) ) ) {

    return;

}


the_post_navigation( array(

    /* translators: %s: title syntax. */

    'prev_text' => sprintf( esc_html__( '%s', 'mytheme' ), '%title' ),


    /* translators: %s: title syntax. */

    'next_text' => sprintf( esc_html__( '%s', 'mytheme' ), '%title' ),

) );

}

endif;


Qyouu
浏览 81回答 1
1回答

慕莱坞森

如果你想在你的帖子的 single.php 中编辑 wordpress 帖子导航,你可以使用:<span> <?php previous_post_link( '%link', '‹ Previous article' ); ?> </span><span> <?php next_post_link( '%link', 'Next article ›' ); ?> </span>如果你想通过设置'next_text'来实现它,你也可以将你的输出放在一个字符串中并使用它:<?php $next_post = '<span>Previous article</span>'; ?>然后将其分配给“next_text”:'next_text' => $next_post如果您阅读 sprintf() 函数https://www.w3schools.com/php/func_string_sprintf.asp ,您可以毫无问题地添加 html 标签。所以它也可以用于:'next_text' => sprintf( esc_html__( '%s', 'mytheme' ), '<span> %title </span>' ),但是你不想拥有这个头衔,所以你实际上不需要这个,如果我没问错的话。编辑:如果你想在你的帖子名称前显示跨度,你可以使用:<?php previous_post_link( '%link', '<span>Previous article</span>'.' %title' ); ?>用点 . 您正在将 span 元素与标题连接起来。所以在你的代码中,你的 the_post_navigation 看起来像:the_post_navigation( array(&nbsp; &nbsp; /* translators: %s: title syntax. */&nbsp; &nbsp; 'prev_text' => sprintf( esc_html__( '%s', 'mytheme' ), '<span>Previous article</span>'.' %title' ),&nbsp; &nbsp; /* translators: %s: title syntax. */&nbsp; &nbsp; 'next_text' => sprintf( esc_html__( '%s', 'mytheme' ), '<span>Next article</span>'.' %title' ),) );
打开App,查看更多内容
随时随地看视频慕课网APP