Wordpress Advanced Custom Field (ACF) - Display field content

/ Published in: PHP
Save to your folder(s)

In this example it checks to see if the page it is on has an ACF named page_title, if so - display it as an H1, and if not, display the WP default page title as the H1

Copy this code and paste it in your HTML
  1. <?php $values = get_field('page_title'); ?>
  2. <?php if ($values) { ?>
  3. <h1><?php the_field('page_title'); ?></h1>
  4. <?php } else { ?>
  5. <h1><?php the_title(); ?></h1>
  6. <?php } ?>

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.