更改各种标题 HTML 标签 – 「Kadence主题」

Kadence主题更改标记并不总是一个好主意,您可以通过更改顺序降序来损害您的可访问性分数。但是,有些人想要这样做或者他们想要更改文本输出。在本教程中,我们将着眼于更改标题 HTML 标签以及在 4 个常见感兴趣区域中的适用标题文本。相关帖子、评论、评论留下回复和小部件标题。这一切都是使用 PHP 过滤器完成的,最好使用代码片段插件来添加这些过滤器。

如何更改类似帖子标题

如果您只想更改“类似帖子”的标题以使用不同的 html 标签,例如 h4 标签,您可以使用此过滤器。

/**
 * Change the similar posts title output.
 *
 * @param string $html the output html.
 */
function custom_similar_posts_title( $html ) {
    $html = '<h4 class="entry-related-title">' . esc_html__( 'Similar Posts', 'custom-text-domain' ) . '</h4>';
    return $html;
}
add_filter( 'kadence_single_post_similar_posts_title', 'custom_similar_posts_title' );

相反,如果您想将文本输出更改为将类似帖子读取为 {post-title},其中帖子标题是当前帖子标题,您可以使用这样的过滤器。

/**
 * Change the similar posts title output.
 *
 * @param string $html the output html.
 */
function custom_similar_posts_title( $html ) {
    $html = '<h2 class="entry-related-title">' . esc_html__( 'Similar Posts to', 'custom-text-domain' ) . ' ' . get_the_title() . '</h2>';
    return $html;
}
add_filter( 'kadence_single_post_similar_posts_title', 'custom_similar_posts_title' );

如何更改评论标题

如果您只想更改“一条评论”的标题以使用不同的 html 标签,例如 h4 标签,您可以使用此过滤器。

/**
 * Change the post comments title output.
 *
 * @param string $html the output html.
 */
function custom_post_comments_title( $html ) {
    $html = '<h4 class="comments-title">';
    $comment_count = (int) get_comments_number();
    if ( 1 === $comment_count ) {
        $html .= esc_html__( 'One Comment', 'kadence' );
    } else {
        $html .= sprintf(
            /* translators: 1: comment count number */
            esc_html( _nx( '%1$s Comment', '%1$s Comments', $comment_count, 'comments title', 'kadence' ) ),
            number_format_i18n( $comment_count )
        );
    }
    $html .= '</h4><!-- .comments-title -->';
    return $html;
}
add_filter( 'kadence_single_post_comments_title', 'custom_post_comments_title' );

相反,如果您想将文本输出更改为将 One Comment 改为 {post-title},其中帖子标题是当前帖子标题,您可以使用这样的过滤器。

/**
 * Change the post comments title output.
 *
 * @param string $html the output html.
 */
function custom_post_comments_title( $html ) {
    $html = '<h2 class="comments-title">';
    $comment_count = (int) get_comments_number();
    if ( 1 === $comment_count ) {
        $html .= esc_html__( 'One Comment', 'kadence' );
    } else {
        $html .= sprintf(
            /* translators: 1: comment count number */
            esc_html( _nx( '%1$s Comment', '%1$s Comments', $comment_count, 'comments title', 'kadence' ) ),
            number_format_i18n( $comment_count )
        );
    }
    $html .= ' ' . esc_html__( 'on', 'kadence' ) . ' ' . get_the_title();
    $html .= '</h2><!-- .comments-title -->';
    return $html;
}
add_filter( 'kadence_single_post_comments_title', 'custom_post_comments_title' );

如何更改留下回复标题标签

要将评论“Leave a Reply”标题标签更改为使用 h4 html 标签,您可以使用此过滤器。

/**
 * Change the comment form title HTML tag.
 *
 * @param array $args the comment form args.
 */
function custom_commentform_title_tag( $args ) {
    $args['title_reply_before'] = '<h4 id="reply-title" class="comment-reply-title">';
    $args['title_reply_after']  = '</h4>';
    return $args;
}
add_filter( 'comment_form_defaults', 'custom_commentform_title_tag' );

如何更改小部件标题标题标签

例如,要将小部件标题标题 html 标签更改为 h4,您可以使用此过滤器:

/**
 * Change the widget area title HTML tags.
 *
 * @param array $args the widget area args.
 */
function custom_widget_title_args( $args ) {
  $args['before_title'] = '<h4 class="widget-title">';
  $args['after_title'] = '</h4>';
  return $args;
}
add_filter( 'kadence_widget_area_args', 'custom_widget_title_args' );

文章标题:更改各种标题 HTML 标签 – 「Kadence主题」,本文链接:https://www.siwihs.com/8561.html。未经允许,禁止转载。

(0)
上一篇 2021-11-14 14:01:01
下一篇 2021-11-14 14:06:17

相关推荐

发表回复

登录后才能评论
分享本页
返回顶部