I'm trying to apply some text to the "Featured Image" box. It works fine for a custom post type, but I can't get a specific piece of text appearing on pages rather than posts.
add_filter( 'admin_post_thumbnail_html', 'foo' );
function foo( $content ) {
global $post_type;
if ( $post_type = 'page') {
$content = '<p>foobar</p>' . $content;
}
else{
$content = '<p>barfoo</p>' . $content;
}
return $content;
}
How can I get WordPress to identify if it is just a page?
I'm trying to apply some text to the "Featured Image" box. It works fine for a custom post type, but I can't get a specific piece of text appearing on pages rather than posts.
add_filter( 'admin_post_thumbnail_html', 'foo' );
function foo( $content ) {
global $post_type;
if ( $post_type = 'page') {
$content = '<p>foobar</p>' . $content;
}
else{
$content = '<p>barfoo</p>' . $content;
}
return $content;
}
How can I get WordPress to identify if it is just a page?
Share Improve this question edited Oct 21, 2019 at 14:03 Chetan Vaghela 2,4084 gold badges10 silver badges16 bronze badges asked Oct 21, 2019 at 13:12 JohnGJohnG 3443 silver badges17 bronze badges 2 |1 Answer
Reset to default 0By using post id you can get post type of current post/page. try below code. i have tested and it is working fine for me.
add_filter( 'admin_post_thumbnail_html', 'foo',10,3 );
function foo( $content, $post_id, $thumbnail_id ) {
if ( get_post_type( $post_id ) == 'page' ) {
$content = '<p>foobar</p>' . $content;
}
else{
$content = '<p>barfoo</p>' . $content;
}
return $content;
}
Let me know if this works for you!
=
sign in theif
statement. – WebElaine Commented Oct 21, 2019 at 13:59