Wordpress 特定帖子id上的触发钩子
在我的wordpress页面上,我有一个展示特色图片的图库。 我想使用wordpress函数文件将HTML添加到特定项中 如果我运行以下代码:Wordpress 特定帖子id上的触发钩子,wordpress,Wordpress,在我的wordpress页面上,我有一个展示特色图片的图库。 我想使用wordpress函数文件将HTML添加到特定项中 如果我运行以下代码: add_filter( 'post_thumbnail_html', 'add_featured_image_html', 10, 1 ); function add_featured_image_html( $html ) { return $html .= '<p>'.get_the_ID().' is the ID</p&
add_filter( 'post_thumbnail_html', 'add_featured_image_html', 10, 1 );
function add_featured_image_html( $html ) {
return $html .= '<p>'.get_the_ID().' is the ID</p>';
}
add_filter('post_缩略图_html','add_特色图像_html',10,1);
函数添加功能图像html($html){
返回$html。=''。获取_ID()。'是ID';
}
我的前端会在我的缩略图下面显示帖子ID。在这种情况下,我希望以Post_ID 19为目标(顺便说一句,这是一种自定义的Post类型)
如果我将代码扩展到:
$id = get_the_ID();
if ($id == 19) {
add_filter( 'post_thumbnail_html', 'add_featured_image_html', 10, 1 );
function add_featured_image_html( $html ) {
return $html .= '<p>'.get_the_ID().' is the ID</p>';
}
}
$id=get_the_id();
如果($id==19){
添加过滤器('post\u缩略图\u html'、'add\u特色图像\u html',10,1);
函数添加功能图像html($html){
返回$html。=''。获取_ID()。'是ID';
}
}
没有显示任何内容
有人能帮我吗?万分感谢 此筛选器的第二个参数是post id 这还没有测试,因为我在打电话。。。但这应该行得通
add_filter( 'post_thumbnail_html', 'add_featured_image_html', 10, 2 );
function add_featured_image_html( $html , $id) {
if ($id == 19){
return $html .= '<p>'.get_the_ID().' is the ID</p>';}
else {return $html}
}
add_filter('post_缩略图_html','add_特色图像_html',10,2);
函数添加功能图像html($html,$id){
如果($id==19){
返回$html。=''.获取_ID()。'是ID';}
else{return$html}
}