Skip to main content

Add Optional Page Settings in WordPress Using Advanced Custom Fields Plugin

By December 18, 2015Blog, Wordpress
WordPress Tutorials by Allure Web Solutions

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

  1. Go to Custom Fields > Add New
  2. Name your field group Page Options (or whatever you want)
  3. Add Field
    1. Label: Hide Title
    2. Type Checkbox
  4. Location: Show this field group if Post Type = Page (or whatever you want)

Page Options ACF

Step 3: Customize your theme

  1. Let’s assume you only want to make the title optional on the page template
  2. Open the page.php template file
  3. Find the location of the title
  4. Put in the code below to optionally show the title
    1. hide_title corresponds to the Name of the Hide Title field in ACF
    2. 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; ?>
allure

Author allure

More posts by allure

Leave a Reply

Designed by

best down free | web phu nu so | toc dep 2017