Skip to content
This repository has been archived by the owner on Sep 22, 2021. It is now read-only.

Latest commit

 

History

History
52 lines (36 loc) · 1.64 KB

wordpress.md

File metadata and controls

52 lines (36 loc) · 1.64 KB

Best Practices: WordPress

General Theme Setup

Editor Styles

Using Advanced Custom Fields

Linking to Pages and Forms in Templates

Try to avoid linking to specific pages, posts, or forms from your template file. While using Post IDs inside templates would normally work fine, we should make our templates flexible.

Rule of Thumb: Build your templates assuming the database could get wiped out at any time or that the rows in the database could get jumbled.

Solutions

To get around using Post IDs in template files, you can take an option-based approach. For example, create an Options page and use a Post Object field type to allow the user to set the correct post, page, or form to load in the template.

Note: By default, Gravity Forms are hidden from the Advanced Custom Fields Post Object field types. To combat this, use Gravity Forms ACF Field.

Example: Printing out a Gravity Form

INCORRECT:

gravity_form(1, false, false, false, null, true, 99);

CORRECT:

$chosen_gravity_form = (int) get_field('contact_form', 'options');
gravity_form($chosen_gravity_form, false, false, false, null, true, 99); ?>

Example: Getting Child Pages

INCORRECT:

function hm_get_team_members() {
    $team_members = hm_get_child_pages(96);

    return $team_members;
}

CORRECT:

function hm_get_team_members() {
    $team_members_page = get_field('team_members_page', 'options');
    $team_members = hm_get_child_pages( $team_members_page->ID );

    return $team_members;
}