尝试在Wordpress中的帖子标题下添加ACF字段(Trying to add an ACF field under the post title in Wordpress)

编程入门 行业动态 更新时间:2024-10-24 20:19:20
尝试在Wordpress中的帖子标题下添加ACF字段(Trying to add an ACF field under the post title in Wordpress)

我的客户正在使用Divi构建器主题,并要求我在分类存档页面的帖子标题下插入一个子标题。 该主题使用the_content()将所有内容拉入页面,因此仅在页面模板中的标题下添加一行不是一个选项。

这可能不是最好的方法,但我使用ACF来添加get_field(“region”)并修改了这个github中的代码。 它在我需要的地方插入字段,但标题是将html作为文本读取。 我现在有一个<br/>在那里,但想用<span class="">替换。 任何想法为什么它不被视为代码?

现场示例>

码:

function gp121028_filter_title( $title ) { $substrings = explode( ' | ', $title ); $title = ( ! empty( $substrings[0] ) ) ? $substrings[0] . '<br/>' . get_field( "region" ) : $title; return $title;

}

My client is using the Divi builder theme and has asked me to insert a subhead under the post title on category archive pages. The theme uses the_content() to pull all content into the pages so simply adding a line under the title in the page templates isn't an option.

This may not be the best way to do it, but I used ACF to add get_field( "region" ) and modified the code from this github. It's inserting the field where I need it, but the title is reading html as text. I have a <br/> in there now but would like to replace with <span class="">. Any idea why it's not being read as code?

live example >

Code:

function gp121028_filter_title( $title ) { $substrings = explode( ' | ', $title ); $title = ( ! empty( $substrings[0] ) ) ? $substrings[0] . '<br/>' . get_field( "region" ) : $title; return $title;

}

最满意答案

没有能力解决它 - 建立它manualy。

Wasnt able to solve it - built it manualy.

更多推荐

标题,title,使用,电脑培训,计算机培训,IT培训"/> <meta name="description"

本文发布于:2023-08-07 06:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1462374.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   标题   帖子   ACF   Wordpress

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!