the_field() function shows the value and it doesn’t get/return anything. Like the_title() and other template tags starting with the_.
It means that:
This line prints the value and $hero variable is empty.
$hero = the_field('hero_title');
This line prints only <h1> tags.
echo '<h1>'.$hero.'</h1>';
What you want is:
echo '<h1>' . get_field('hero_title') . '</h1>';
Related Posts:
- Show/hide Widgets in Dashboard Based on Current Advanced Custom Fields Option
- How to use max and min values of custom fields
- Redirect to another page using contact form 7? [closed]
- How to retrieve the values of a sub-field in the first and last row of an (ACF) repeater inside function?
- Programmatically add Yoast meta description after post save
- Perform function on publish AND save (not just save)
- Reference multiple style sheets, clearing styles for permalink page, custom fields for css
- update_post_meta not working in function
- How to display custom field in woocommerce orders in admin panel?
- Is it ok to use a function to output the text domain name in a wordpress theme
- functions.php inject inline css
- TinyMCE custom styles remove class when switching styles
- Return only top-level navigation items from a menu using wp_get_nav_menu_items
- Overriding core functions in child theme
- Add inline css to theme
- Dequeue Scripts and Style for Mobile not working?
- Assign category using custom field?
- Add external js file to footer with id
- How to add background image control to page admin controls?
- Best Practice for Syncing Local Development With Staging Development [closed]
- How to use thumbnails in gallery?
- Customizer field value into functions.php variable
- Logic to Print/echo a css class only for 1st post and ignore all post after 1st? [closed]
- is_dynamic_sidebar always returns true while using Jetpack visibility
- Auto delete post if certain custom field data is empty
- Why does the ‘wp_nav_menu’ function work only until a menu is created?
- Run function when WordPress new multisite is created or ACF field is updated
- is_customize_preview() like function to check if Customizer “Live Preview” in JavaScript
- Override a theme function in a child theme?
- Pulling Twitter RSS feed not working as expected (fatal error)
- Use register_setting() in a loop
- Get Current Post ID in functions php, meta query filter
- Add dynamic links in WordPress custom theme
- WordPress menu link doesn’t work properly
- Search filter by Post title OR Meta Title Value [duplicate]
- Removing custom meta data
- how can I edit flexslider in woocommerce. [Urgent]
- Custom Attachment Caption Fields
- Jquery implementation not working on page reload
- Usage of theme name in functions
- Trying to retrieve post meta
- WebP Fallback for Inline Background Image in Style Attribute
- WordPress function saves a post twice and updates all posts
- Check if the image size is available and if not use ‘full’ image size
- Prevent custom field from being updated after first publish
- Remove Custuomize Sections
- Can we create our own theme’s function.php?
- get_pages() Returns Only One Item
- Add php code to wp_print_scripts?
- Getting the teaser text without overriding global variables
- How to make custom comment fields required
- “options.php” not found
- Using two loops in one WordPress template
- What is the correct way to include my new functions and scripts in WordPress?
- wp_nav_menu work in functions.php but not in the theme
- contact form in template with jquery,validate and ajax
- Why I can’t load my JavaScripts using an hook inside my functions.php file?
- Display ACF category image on archive and single template files
- How to Display WooCommerce Product Price in WooCommerce Archive
- Woocommerce Variable Product Dropdown for Custom Shop Template
- Delete images from media library when user deletes an image from ACF Gallery
- Featured Image and Tags problem
- WordPress Function Assistance with Loop
- How to show ACF value under post/page title in wp-admin
- Exclude specific post from query
- wp_set_object_term via js btn frontend
- Advanced method to control cache of enqueued style/script
- WordPress wp_dequeue_script remove all other scripts
- Filter works on last selection but no others
- Populate Product Regular Price with a calculated ACF Field Value
- How to update an image attachment’s alt text from a custom field when saving a post?
- Why does echo on functions.php not yield result in source code?
- Assign IDs to headings in ACF using functions.php
- get_field() with ID in one signal filter not working
- Creating a “Related Meta” type field?
- How would I correctly implement a new if statement in a child functions file?
- Echo a String Based On Geolocation? [Woocommerce || ACF]
- Remove External Links from WordPress posts Using add_filter() in Theme functions.php
- How to retrieve image IDs from shortcode content?
- How To Show Shortcodes In WordPress Custom Fields?
- Class::$template_dir_path=get_template_directory();
- Return ACF Field value function
- Providing fallback function and allow override by plugin
- Post date on Custom field
- Different body image backgrounds on different pages, posts and categories
- Language switcher for subdomains
- How to add next height number in Order Attributes inside the Add new page. [duplicate]
- wp_nav_walker that interacts with widgets to setup mega menu
- How to display data from custom fields in my custom shortcode?
- Allow tags and attributes in post and pages content
- Syling Custom Fields echo’s from from functions.php
- does acf_save_post cause endless loop?
- Call ACF data from functions.php [closed]
- Add custom css to theme
- Why don’t ‘wp_nav_menu’ CSS classes work until a menu is created?
- Change Post status based on custom field date +1 day
- Update post meta with wp cron
- Setcookie not setting cookies anywhere except admin
- How to use webpack in WordPress theme? I want some scripts to load in the footer, some in the header and some with script parameters
- How can I able to exclude ‘Category’ and ‘Tag’ slug from the URL in WordPress without reloading to new site?