Hook into postbox_classes
. postbox_classes
is the function which will output the classes for the metabox.
apply_filters( "postbox_classes_{$page}_{$id}", $classes )
Your code could look like this:
add_action( 'add_meta_boxes', 'add_my_metabox' );
function add_my_metabox() {
$id = 'my-metabox';
$title="My Metabox";
$callback = 'my_metabox_content';
$page="post";
add_meta_box( $id, $title, $callback, $page );
add_filter( "postbox_classes_{$page}_{$id}", 'minify_my_metabox' );
}
function my_metabox_content() { ... }
/*
* $classes is an array
*/
function minify_my_metabox( $classes ) {
if ( isset( $_POST['my_condition'] ) && 'my_condition' == $_POST['my_condition'] ) {
array_push( $classes, 'closed' );
}
return $classes;
}
Related Posts:
- How to activate “Description” metabox for menu item programmatically?
- Displaying Saved Meta Box Data in Drop Down with selected()
- radio button is checked but display not check
- How to hide, and not to remove the attributes metabox?
- get_post_type() in in_array doesn’t work for some reason
- How to hide a plugin metabox for non admins when a user adds a new post
- Custom Attachment Caption Fields
- Adding jQuery datepicker to Custom Post Type Metabox [closed]
- Use a shortcode to display custom meta box contents
- How to change a meta value (of a published post) after X days.?
- sort metabox columns in listing Single
- How to avoid saving empty data to sql while using add_meta_box
- Save Meta when custom Taxonomy Saves
- Render metabox gallery in frontend
- Creating a “Related Meta” type field?
- Meta Box value not been pulled in
- Decimal stripped from metabox number
- Adding a second email address to a completed order in WooCommerce [closed]
- Possible to search by author name with default WordPress search function?
- Advantages and disadvantages of using automatic-feed-links
- current_cat_ancestor Alternatives
- Change number of posts to show on Archive page (custom post type)
- How to use wp_get_recent_posts with many post types?
- Add body class of category parent
- Roles & capabilities GUI that does not create separate table
- Why get_header() or get_footer() does not run twice if called in the same php file?
- Set image size on media and text block with a function
- How to update WordPress and plugins at specific day and time in PHP?
- Max file size not updating
- How to override filter in child theme?
- Use Exact Image Size using add_image_size
- How can I tell when a user is logged in?
- Enqueue Style in Functions.php
- How allow users to save list of posts?
- Formatting Multiple add_theme_support Arguments
- How to: add option to add more checkboxes on custom post type
- Limit posts only on home page – ideally in functions.php
- Make Categories a Dropdown Menu in Media Library
- How to add css class to image attached in all the posts?
- If is multiple page templates
- Is there a way to add a class to non current menu item?
- What will happen if I delete the functions.php file?
- how to add an image to the footer?
- How to properly add function called by action-hooked function to functions.php?
- Get Current User info using wp_localize_script, in functions.php
- How to add new embed handler not supported by oembed?
- How do I permanently Disable Attachment Post URL
- Need to add class=”lightbox” for every single post image
- Child Theme files – what is needed?
- How do I add Bootstrap and LESS to my migrated WordPress site?
- Stuck on maintenance mode
- Publish/Update post is changing image links from file url to post url
- Linking text within textarea of custom meta box
- How to display custom option field in woocommerce orders in admin panel?
- Best practices regarding the creation of custom widgets?
- Multiple Loops Meta Data
- Update user meta of author when post content is viewed
- If ACF field is empty show different value [closed]
- Why does this update_post_meta function not delete the custom field itself?
- How i can put $_GET codes in function.php?
- Get post meta retrieving wrong value
- Is there a way to direct unregistered user to registration page when click a link?
- Auto log in hook is requiring a page refresh
- I want to display latest post in marquee [closed]
- Add php code to wp_print_scripts?
- How to get an attachment id from a filename
- how to get the post ID from wp_insert_post
- Remove ‘page-numbers’ class from prev and next tags
- How can I set the SRC URL of the custom logo image?
- The Capability to choose post/page template
- The_content and Preg_replace in loaded Iframe [closed]
- WooCommerce -> wc_enqueue_js not working [closed]
- Use existing image sizes for WooCommerce
- Add a mature content warning to first-time visitors
- User meta and public function security
- Show Featured Image in else statement
- Any adverse effects of adding apply_filters to a function?
- How can I remove page titles without removing the link in the navigation bar in twentyeleven?
- Simplest Way to Build Custom Archives Page?
- wordpress built-in Jalali date convertor
- Change WooCommerce Payment Options From Radio Buttons to Dropdown Menu
- WordPress Function Assistance with Loop
- Populate acf-field, depending on block name
- Add Change role button for list of user in an event
- Exclude admins from query get posts
- I am trying to set post terms to a custom taxonomy
- Classic TinyMCE messing up only Contributor’s HTML
- Reference multiple style sheets, clearing styles for permalink page, custom fields for css
- Add schema to Search result page’s body. Tried using is_search
- Show users last read posts for each user?
- Disable links to images only if link is an image
- WordPress Javascript Widget jQuery Dependency Issue
- Allow tags and attributes in post and pages content
- Syntax for a function in order to get post’s title in JSON encoded response [closed]
- Comment Function
- Will my WordPress site become vulnerable after adding this functions which allows more HTML tags for subscribers?
- Add product to cart from functions.php
- How to resize image from import image url?
- Vimeo video play button color function
- Loading newest dependency javascript module file in functions.php