admin管理员组文章数量:1279042
I am trying to add classes to my metabox. How could I apply this to both post and pages? $posts variable? Do I need to add filter twice, once for each post type?
$id = 'my-metabox-api';
$posts = array('post', 'page');
add_meta_box($id, 'My Video Player', 'add_metabox_api', $posts, 'normal', 'low');
add_filter( "postbox_classes_{$posts}_{$id}", 'my_custom_mb' );
function my_custom_mb( $classes ) {
array_push( $classes, 'closed' );
return $classes;
}
I am trying to add classes to my metabox. How could I apply this to both post and pages? $posts variable? Do I need to add filter twice, once for each post type?
$id = 'my-metabox-api';
$posts = array('post', 'page');
add_meta_box($id, 'My Video Player', 'add_metabox_api', $posts, 'normal', 'low');
add_filter( "postbox_classes_{$posts}_{$id}", 'my_custom_mb' );
function my_custom_mb( $classes ) {
array_push( $classes, 'closed' );
return $classes;
}
Share
Improve this question
asked Nov 6, 2021 at 20:55
ToniqToniq
4476 silver badges15 bronze badges
1 Answer
Reset to default 0Do I need to add filter twice, once for each post type?
Yes! you can't insert an array into a string, if you could it wouldn't result in a matching filter name anyway. The filters for posts and pages are different filters. You need to add them separately.
e.g. postbox_classes_post_my-metabox-api
versus postbox_classes_page_my-metabox-api
If I had to guess, your current code results in this filter name: postbox_classes_array_my-metabox-api
本文标签: plugin developmentaddfilter postboxclasses multiple post types
版权声明:本文标题:plugin development - add_filter postbox_classes multiple post types 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741231969a2362276.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论