我正在使用此功能:
if ( $id && $post && $post->post_type == 'business-areas' )
{
$pieces = explode(' ', $the_title);
$last_word = trim(strtolower(array_pop($pieces)));
if($last_word != 'jobs')
{
$the_title = $the_title . ' jobs';
}
}
return $the_title;
如果标题的最后一个单词不是JOBS,这基本上是将JOBS单词附加到自定义帖子类型业务区域的任何标题上。
是否可以向其中添加模板查询?
因此,基本上,如果自定义帖子的页面模板是DEFAULT,请执行此操作;如果页面模板不是DEFAULT,请不要这样做。
答案 0 :(得分:0)
将此代码放入functions.php
文件中。
function add_label_to_post_title( $the_title = '' ) {
global $post;
if ($post && $post->post_type == 'business-areas' )
{
$pieces = explode(' ', $the_title);
$last_word = trim(strtolower(array_pop($pieces)));
if($last_word != 'jobs')
{
$the_title = $the_title . ' jobs';
}
}
return $the_title;
}
add_filter( 'the_title', 'add_label_to_post_title' );