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
- How to enable custom fields for pages (if not a bad practice)?
- Add a Jquery Datepicker to custom field in post edit
- Custom per-page sidebar widgets .. possible?
- How to add new custom page or post blocks?
- Transients vs CRON +Custom Fields: Caching Data Per Post
- How to update serialized data in the user meta data
- Unable to save datetime custom meta field using update_post_meta() function
- Guest Author – How can I use custom fields to create guest author link?
- Adding a Nav menu to post admin
- Create additional short URL with custom field and 301 redirect
- enabling custom fields in admin?
- get_post_meta fields don’t show up on posts page
- Using custom fields in a filter hook
- Function to change meta value in database for each post
- Using WP Query to search by multiple meta fields
- Get aggregate list of all custom fields for entire blog
- How to Identify the Source of a Custom Field?
- Include woocommerce custom field value in front-end search result
- MySQL Query that looks for post with Custom Field, then changes Category
- two custom fields question
- How to save multiple options from a dropdown in user profile
- How to display multiple images in custom field
- How to show a gloabl message on a user profile page (in back end)?
- Create Pop-Up Box with Custom Field Content Inside the Loop
- Display the contents of a custom field of a page on their child
- Login WP – Connect single field to an external api
- adding extra wordpress user info from registration form
- Custom Meta Box (SELECT) Not Saving
- jQuery – Automatic event trigger does not **really** check my form
- Display URL in a Custom Field
- Add first url to custom field on publish_post
- Use meta_query to get title of associated post
- Limits, not all post are showen when querying for posts by view count
- get_post_meta() retrieves meta from a specific post on pages, not the page currently viewed
- Advanced Custom Fields WYSIWYG More tag
- How to make custom fields respect paragraph breaks
- WordPress set custom field to true, sets all others to false?
- modify wordpress custom field value – strip character if exists
- Looping inside block return
- Sortable Custom Columns not sorting correct
- Is there a size limit to the value you can save in a custom field?
- Sort posts by clicks on download button
- Pass PHP through redirect and custom fields
- MetaBox not saving after empty
- How can I create a profile field group that the user can’t see?
- Showing Custom Fields on Parent Page
- Custom Theme Fields in Settings Menu – apply filters to one of those fields?
- Custom wpdb query – how to sort post by another table meta_count
- Show Custom Field of Current Page in For Loop
- Custom Field & Gravity Forms [closed]
- Redirect DRAFT Posts to a Custom URL (Custom Field) : Currently 404 Page
- multiple meta_query and orderby question
- Add a custom field to my custom post type and then get posts which are before the given date in the custom field
- Custom User Dashboard
- SQL query to change the value of a Custom Field
- Custom meta POST request fired twice when updating a post in Gutenberg
- want to add video upload option for front end user
- Adding fields to attachment – only shows when inserting new attachments
- Check if value exists before saving
- Get meta value when the page is a blog archive
- Add Image With Changeable Link in Custom Field [closed]
- Populate a select box with data stored in the database?
- Create download page from post option link
- How to Pull Out Twitter Summary Data in other areas of my template?
- query specific posts according their custom fields, using sql SELECT
- Meta_query not filtering posts
- Custom fields driven site. I want to make a visual editor driven page template. How?
- Should I use a Meta field or custom table?
- Rewrite Custom Fields url
- Cannot save values to custom fields for variations on Woocommerce 2.4.6
- Associate an image with a post to show it in a slideshow
- Dynamic background image used in css after selector
- How to apply Local Business Google Schema dynamically on a Custom Post single template?
- Match submitted array fields with the MYSQL database fields to update them correctly in PHP
- Best way for managing images of ads banners
- Crop custom image size vs actual size
- Multiple permalinks for a single post from custom field
- Search for meta_query does not return any result if combined with title
- get_the_ID() retrieves same ID on Gutenberg’s Query Loop
- How to conditionally display an ACF custom textarea contents only to those users chosen from an ACF User field
- Custom fields empty after refreshing page
- Custom date column in user table not sorting correctly