Adding Custom Fields
Master WordPress custom fields with WYSIWYG editors
What You'll Build
Custom Page Templates
Create specialized templates with multiple content areas beyond the standard WordPress editor. Build flexible layouts for different page types.
WYSIWYG Custom Fields
Implement user-friendly editors for custom content areas using Advanced Custom Fields plugin. Enable client-friendly content management.
Dynamic Content Areas
Set up left and right column custom fields that display dynamically based on page template selection and custom field values.
MAMP vs XAMPP Database Setup
| Feature | MAMP (Mac) | XAMPP (Windows) |
|---|---|---|
| Database Password | root | leave blank |
| Username | root | root |
| Default Port | 8888 | 80 |
| Access URL | localhost:8888 | localhost |
WordPress Installation Process
Database Configuration
Enter database name 'landm' with appropriate credentials for your local environment (MAMP or XAMPP)
Site Setup
Configure site title as 'L&M Classic Cars' with admin username 'landmAdmin' and password 'student'
Search Engine Settings
Uncheck search engine indexing to prevent local development site from appearing in search results
WordPress themes can have multiple templates for different page types. The 'Bottom Columns' template we're using provides additional content areas beyond the standard page template.
Notice that below the loop are two divs: rightColumn and leftColumn. This is where our custom fields will go.
Template Structure
Standard WordPress Loop
Displays the main page content using the_content() function within the traditional WordPress loop structure.
Custom Field Containers
Two additional div containers (rightColumn and leftColumn) ready to display custom field content dynamically.
Custom Fields Setup
Enable Custom Fields
Access Screen Options and check 'Custom Fields' to reveal the custom fields interface at the bottom of the page editor
Add Field Pairs
Create 'right-column' and 'left-column' custom fields with test content to establish the field structure
Select Template
Choose 'Bottom Columns' template in Page Attributes to enable the custom field display functionality
The get_post_meta() function requires three parameters: post ID, custom field name, and return format (true for string, false for array). This function retrieves and displays custom field values.
Code Implementation
Function Parameters
get_post_meta($post->ID, 'field-name', true) retrieves custom field data for the current post with string output format.
Loop Placement
Custom field divs must be placed inside the WordPress loop to access the current post's ID and display the correct content.
Advanced Custom Fields Plugin Setup
Install Plugin
Search for and install 'Advanced Custom Fields' by Elliot Condon from the WordPress plugin repository
Create Field Group
Add new custom field group titled 'Bottom Columns' with left-column and right-column WYSIWYG editor fields
Set Location Rules
Configure the field group to display only when 'Bottom Columns' page template is selected
Content Input Methods
| Feature | WYSIWYG Editor | HTML Source |
|---|---|---|
| User-Friendly | Visual editing | Code required |
| Media Upload | Built-in button | Manual HTML |
| Formatting | Toolbar options | Raw HTML tags |
| Client Suitable | Yes | No |
Key Takeaways
