admin管理员组文章数量:1125785
I need to show a custom Field in a title (CPT) I have this code
function wpse_224340_document_title($title){
global $post; // make sure the post object is available to us
if(is_singular('mec-events')){ // check we're on a single post
$release_author = get_post_meta(get_the_ID(), 'mec_fields_2', true);
if($release_author != ""){ $title["title"].= " (" . $release_author. ")"; }
}
return $title;
}
But it doesn´t work, someone can help me with my problem?
I need to show a custom Field in a title (CPT) I have this code
function wpse_224340_document_title($title){
global $post; // make sure the post object is available to us
if(is_singular('mec-events')){ // check we're on a single post
$release_author = get_post_meta(get_the_ID(), 'mec_fields_2', true);
if($release_author != ""){ $title["title"].= " (" . $release_author. ")"; }
}
return $title;
}
But it doesn´t work, someone can help me with my problem?
Share Improve this question edited Feb 5, 2024 at 13:50 shanebp 5,0836 gold badges27 silver badges40 bronze badges asked Feb 5, 2024 at 11:03 LaurapnunezLaurapnunez 11 bronze badge1 Answer
Reset to default 1Use the wp_title
filter, which passes the current title, separator, and location as arguments. It then appends the custom field value to the title if the conditions are meet. For more details :- Visit Link wp_title
function wpse_224340_document_title($title, $sep, $seplocation) {
global $post;
// make sure the post object is available to us
if (is_singular('mec-events')) { // check we're on a single post
$release_author = get_post_meta($post->ID, 'mec_fields_2', true);
if ($release_author !== "") {
$title .= " (" . $release_author . ")";
}
}
return $title;
}
add_filter('wp_title', 'wpse_224340_document_title', 10, 3);
本文标签:
版权声明:本文标题:Custom Field in Page Title 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736662995a1946513.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论