I don’t know if you need to hide the element completely, as in “never display it”, or if you need to hide it conditionally with JavaScript– say, to get a toggle effect. Either case is similar and would use get_post_meta()
.
To conditionally display the data use something like:
$m = get_post_meta(get_the_ID(),'my_meta_key');
if(!empty($m)) {
echo '<div>your data</div>';
}
If you want something that you can toggle with JavaScript use:
$m = get_post_meta(get_the_ID(),'my_meta_key');
$str="<div %s>your data</div>";
if(!empty($m)) {
$str = sprintf($str,'class="'.$m.'"');
}
echo $str;
Related Posts:
- How to add a custom field in the advanced menu properties?
- Adding a custom field to the site identity menu
- Add meta data to the menu
- Create a select drop down of available menus
- Dynamic User State & City selection
- Creating a custom menu/widget area
- Nav Menu – Add class based on meta keys
- Add image to menu item with ACF
- Declaring in variables [closed]
- How to add a custom field in the advanced menu properties?
- Walker class for sub-menu with ACF fields
- Populate wordpress menu with link to custom field value (file download)
- Show Custom field value instead of title in WP Menu
- How to make menu country specific?
- Override edit_custom_walker.php to conditionally show input depending on menu position
- How to use page metadata while using wp_list_pages()?
- Add custom fields to specific menus
- Add CSS class to posts with certain meta key
- Apply the_content filter to a custom field with multiple values
- Meta Query with AND & OR?
- Adding another state (spam, reject, approve) to wordpress comments?
- WP doesn’t show Array Custom Fields?
- Filter archive.php by custom meta
- How do I search an array stored in a custom-field using WP_Query?
- Get updated meta data after save_post hook
- Custom text-only header
- How to save custom fields for attachments
- How to get a meta value from all post
- Exclude custom post type from search by custom field value?
- Currency (price) formating on custom fields
- Adding Custom Text Area to WooCommerce Product
- Get multiple custom field values in a $wpdb query [duplicate]
- add meta box using function.php
- Order by value in serialized custom field
- Custom image sizes for custom field media uploads
- converting custom field date format
- Buddypress Add unserialized Profile Fields in Members Loop [closed]
- Add Paypal Button programmatically
- How do I use wp_query for WordPress search?
- Conditionally hide or show woocommerce product variation in fontend by custom field
- custom meta box text field: how to limit to alpha or numeric only
- Accessing loop functions (e.g the_title or the_content) from post ID
- Create an Array of Specific Custom Post Meta
- custom avatar removal
- Excluding Specific Fields from Profile Builder Registration Form
- How to create a shortcode to print specific values stored in a post meta array?
- How to add upload video option in wordpress for user?
- Set post to unpublished after one week depending on condition
- Custom WP_Query for WordPress Search Results with meta_query
- Change order of posts
- Meta Query And/Or
- URL Rewrite fires when retrieving a custom value?
- How to store post meta in an array
- Efficiently sort only certain categories by custom field
- How can I do a variable for meta_query?
- Set checkbox as checked by default in a metabox
- ACF form edit front end post title does not change permalink
- How to list Category list in ACF Pro’s Select Field to choose from [closed]
- Can I use a Custom Field as the Featured Image URL?
- Display custom field & value correctly on page
- Displaying custom filed content instead of post content
- Copy price categories to custom field
- Save all the post tags inside a custom field
- Sanitize user input fields before wp_insert_post
- Use Advanced Custom Fields – replace line of code that hardcodes the tag into the template
- How to update a custom field in all posts with the value of another custom field in the same post?
- Advanced Custom Fields and Post Meta Fields Relation
- Set featured image from custom field URL
- Best Way to get facebook share count and update using wp_schedule_event or any other method
- Filter posts by custom field (Advanced Custom Fields)
- KEY and VALUE custom field issue
- Trying to implement AJAX into my admin pages. Am I improperly enqueue and localizing my scripts?
- Stripping and/or altering the content of a custom field (video URL)
- Custom field outside the loop and inside an array
- WP E-Commerce Custom Meta > Serialized array
- Display Additional Info
- Custom meta fields and meta keys
- HTML for adding a meta box (basic text field) to page editor?
- Add link to wordpress field data
- Adding text box with add_meta_box
- Save Taxonomy of Post via custom Taxonomy Select Dropdown
- use custom field value as featured image
- adding autosave feature to custom fields
- (woocommerce) How to get product id form order id & then retrieve custom meta linked to product?
- Is it possible to manage Multiple Custom Fields with Some Relations
- Retrieving and inserting data in custom fields
- How to add custom fields to images for image source text and URL
- Echo out custom fields in comments
- Why WordPress takes time to make request to save post?
- Show comon custom field results?
- Filter query based on date in custom field
- Display Child Page with custom fields within Parent Page
- Convert all dates in field to Unix time, except those already in Unix time
- get_post_custom_values not working
- Pagination not displaying correct number of pages
- Show div based on custom meta value
- add multiple values (array) to post meta_input
- Assign class to Drop Down Selections in WooCommerce Products Custom Fields
- Show/Hide Featured Image or replace it with custom field [closed]
- Archive for custom fields?