In this post I will talk about using the Advanced Custom Fields (ACF) plugin to make certain parts of a WordPress page option in your custom theme. It’s actually quite easy. In my example, I will show how to make the page title an optional item. You can follow the same pattern for any other parts of a page that you want to make optional.
Step 1: Install ACF Plugin
Step 2: Create Page Options Field Group
- Go to Custom Fields > Add New
- Name your field group Page Options (or whatever you want)
- Add Field
- Label: Hide Title
- Type Checkbox
- Location: Show this field group if Post Type = Page (or whatever you want)
Step 3: Customize your theme
- Let’s assume you only want to make the title optional on the page template
- Open the page.php template file
- Find the location of the title
- Put in the code below to optionally show the title
- hide_title corresponds to the Name of the Hide Title field in ACF
- The logic of the code: If the hide_title checkbox isn’t checked, display the code below, otherwise (if checked), don’t display the code below
<?php if ( !get_field('hide_title') ) : ?> <h1 class="page-title" itemprop="headline"><?php the_title(); ?></h1> <?php endif; ?>