html - 如何将元数据字段保持在一行
问题描述
我正在尝试为我的帖子自定义元数据。具体来说,我想将分隔符从默认的正斜杠 (/) 更改为垂直线 (|)。我还想在显示的日期之前添加“更新”一词。而且,我想保留显示阅读时间的选项。(*仅供参考:我基本上对编码一无所知,只是试图覆盖从 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 个字段。
我需要在第二个代码块中进行什么更改才能像第一块代码一样将所有内容保持在一行上?
谢谢你的帮助!
解决方案
推荐阅读
- vba - 使用 VBA 登录和验证 OneDrive
- c++ - 没有太多冗长的虚拟模板解决方法
- r - “观察次数 <= 随机效应数”错误
- html - 在我的样式表中将 font-family 设置为“Goudy Trajan Regular”不起作用
- amazon-web-services - 如何使用 cloudfront/route53 将通配符域 (*.example.com) 指向 s3 存储桶
- node.js - 谷歌风格分页
- javascript - 如何在 javascript 中重复相同的节点来编辑 html?
- php - Laravel foreach 输出不完整
- java - 配置 MysqlConnectionPoolDataSource (Java) 时必须设置哪些配置属性?
- json - 使用任意键/值对将 JSON 解组为结构