首页 > 解决方案 > 如何将元数据字段保持在一行

问题描述

我正在尝试为我的帖子自定义元数据。具体来说,我想将分隔符从默认的正斜杠 (/) 更改为垂直线 (|)。我还想在显示的日期之前添加“更新”一词。而且,我想保留显示阅读时间的选项。(*仅供参考:我基本上对编码一无所知,只是试图覆盖从 Astra 输出的元数据)

我使用这段代码来更改分隔符(在一篇关于如何在 Astra 主题中自定义帖子元的帖子中找到):

add_filter('astra_single_post_meta', 'custom_post_meta');
function custom_post_meta($old_meta)
{
 $post_meta = astra_get_option('blog-single-meta');
 if (!$post_meta) return $old_meta;
 
 $new_output = astra_get_post_meta($post_meta, "|");
 if (!$new_output) return $old_meta;
 
 return "<div class='entry-meta'>$new_output</div>";
}

请参阅图 1 中的输出 - 看起来很棒!

输出分隔符的新代码

这很接近,但仍需要在日期之前添加“更新”。所以,我使用了这段代码(来自上面提到的同一篇文章):

function astra_post_date()
{
 $format = apply_filters('astra_post_date_format', '');
 $published = esc_html(get_the_date($format));
 $modified = esc_html(get_the_modified_date($format));

 $output = '<p class="posted-on">';
 $output .= 'Updated: <span class="published" ';
 $output .= 'itemprop="datePublished">' . $published;
 $output .= '</span>';
 $output .= '</p>';
 
 return apply_filters('astra_post_date', $output);
}

请参阅图 2 中的输出 - 内容完美,但格式错误。无法弄清楚如何编辑代码以在同一行上获取所有 3 个字段。

添加“更新”的新代码的输出

我需要在第二个代码块中进行什么更改才能像第一块代码一样将所有内容保持在一行上?

谢谢你的帮助!

标签: htmlcsswordpressmetadata

解决方案


推荐阅读