SlideShare a Scribd company logo
1
Do it in code!
A guide to creating a custom site
structure plugin in WordPress.
Presented by:
Peter Hebert
Rex Rana Design and Development Ltd.
Rex Rana
2
What is site structure?
Post Types
Metaboxes and Fields
Taxonomy
Menus
Permalink Structure
Rex Rana
3
Why a custom plugin?
Functionality should live in code, not the database
Themes for presentation, plugins for functionality
Manage code in version control system (git, svn)
Code Portability / Deployment
dev / staging / production
re-use for multiple websites / different clients
4
Our Sample Plugin
We'll create a Film listing (like IMDB)
Custom Post Type: Film
Custom Taxonomy: Genre
Metabox: Film Info
Fields: Release Date, Duration, Director
https://github.com/rexrana/my-custom-structure
5
WordPress core functionality
Not easy to use — you have to do all the heavy li ing
CRUD functions (create, read, update and delete)
Callback functions with HTML to display fields in admin
Sanitization / validation of input
nonces
It's a lot to remember — time could be better spent
6
Thankfully, there’s a better way!
Many tools exist for simplifying the creation of site structure:
Plugins (Advanced Custom Fields, Pods, etc.)
Most have an export to code functionality
Developer libraries: CMB2, Custom Meta Boxes
Code Generators: GenerateWP, WP-CLI scaffold command
7
GUI-based structure plugins
Create your structure in the admin, then export to code.
export to XML (v4 and below), JSON (v5), PHP
framework
Migrate: Packages
Pods Deploy - uses WordPress REST API (beta)
/ Packager
Advanced Custom Fields
Pods
Toolset
Embedded Toolset
8
Developer library: CMB2
github.com/WebDevStudios/CMB2
Toolkit for building metaboxes, custom fields, and forms
Takes care of all the hard stuff for you
Declare metaboxes and fields using arrays of parameters
32 field types included, with API to declare your own
Use on Post Types, Options Pages, User Profiles
even on the front end of your site
9
Developer library: Custom Meta Boxes
github.com/humanmade/Custom-Meta-Boxes/
Framework for easily adding custom fields
works similarly to CMB2 (parameter arrays)
(seems to) only work on post edit pages
fork of original CMB (predecessor to CMB2)
20 field types included, plus repeater field
features a basic 12 column grid system to align fields
10
Code Generators: GenerateWP
generatewp.com
Form-based wizards for generating code compliant with
WordPress coding standards
Select a tool, fill in the form, generate the code
Copy ready-to-use code directly to your plugin.
11
Code Generators: WP-CLI 'scaffold'
wp-cli.org/commands/scaffold/
Command within WordPress command-line interface (CLI)
Generates starter code for themes, plugins, unit tests, post
types and taxonomy.
Limited - cannot specify advanced parameters, only gives
minimal config with defaults
Provides a quick start-off point
12
WP-CLI Scaffolding Examples
Run commands from within site directory
'Film' post type
wp scaffold post­type film ­­label=Film ­­textdomain=structure 
­­dashicon=editor­video ­­plugin=my­custom­structure
'Genre' taxonomy
wp scaffold taxonomy genre ­­post_types=film ­­label=Genre 
­­textdomain=structure ­­plugin=my­custom­structure
13
Putting it all together
If using ACF or CMB2 :
Install plugin in normal way, or:
Download to a subdirectory, include in your plugin's main PHP file
Create separate PHP files for each of: Post Types, Taxonomy,
Metaboxes/Fields
include these files in your main plugin PHP file
this makes items easier to find, comment out or remove
14
Developer library includes
Advanced Custom Fields
if( file_exists( dirname(__FILE__).'/lib/advanced­custom­
fields/acf.php' ) ) {
include_once( 'lib/advanced­custom­fields/acf.php' );
}
CMB2
if( file_exists( dirname(__FILE__).'/lib/cmb2/init.php' ) ) {
    include_once( 'lib/cmb2/init.php' );
}
15
Includes for declaring structure
include_once('post­types/film.php');
include_once('taxonomies/genre.php');
// METABOXES AND FIELDS
/* using WordPress core functionality */
include_once('inc/wp­fields.php');
/* using ACF */
include_once('inc/acf­fields.php');
/* using CMB2  */
include_once('inc/cmb2­metaboxes.php');
16
Resources
CMB2: THE METABOX STRIKES BACK (Justin Sternberg)
Plugin comparison - Custom Post Types / Fields
(Google spreadsheet)
Custom Post Type Permalinks (plugin)
story w.com/cmb2-metabox-strikes-back
goo.gl/o7kU9s
wordpress.org/plugins/custom-post-type-permalinks/
17
Thank You
Find me online:
rexrana.ca
peterhebert.com
@RexRanaDesign
@peter_hebert
peterhebert
rexrana

More Related Content

PDF
Gradle-based Android Build System
PPT
Lunch and learn as3_frameworks
PPT
Developing for the BlackBerry PlayBook using Flex Builder Burrito
PPS
Simplify your professional web development with symfony
KEY
Philip Arthur Moore: Best Practices — On Breaking and Fixing WordPress Themes
PDF
Danielle Resume-2015 linkedin
PPTX
Adultsent2013
PDF
Du-an-50-khoa-hoc-wordpress-mien-phi-chuan-seo
Gradle-based Android Build System
Lunch and learn as3_frameworks
Developing for the BlackBerry PlayBook using Flex Builder Burrito
Simplify your professional web development with symfony
Philip Arthur Moore: Best Practices — On Breaking and Fixing WordPress Themes
Danielle Resume-2015 linkedin
Adultsent2013
Du-an-50-khoa-hoc-wordpress-mien-phi-chuan-seo

Viewers also liked (14)

PPTX
Dr 2013
PPTX
Youth2014
PPT
機算機概論期末報告 無線網路技術 Wi-Fi & WiMAX
PDF
Nasreen Resume
PDF
Sage 100 User Group
PDF
Sage 300 Inventory Management VS. A Best-of-Breed Warehouse Management Soluti...
PPTX
A2 intro recap [sept 2013]
PDF
El espíritu de la conectividad ...desde la perspectiva emprendedora
PPTX
NFOAP 2013
PPTX
L3 (qu3 summary)
PDF
Shruti Panda Resume -Updated
PPTX
Antiepileptics
PPTX
Aims and Factors of Sentencing
DOC
Beena
Dr 2013
Youth2014
機算機概論期末報告 無線網路技術 Wi-Fi & WiMAX
Nasreen Resume
Sage 100 User Group
Sage 300 Inventory Management VS. A Best-of-Breed Warehouse Management Soluti...
A2 intro recap [sept 2013]
El espíritu de la conectividad ...desde la perspectiva emprendedora
NFOAP 2013
L3 (qu3 summary)
Shruti Panda Resume -Updated
Antiepileptics
Aims and Factors of Sentencing
Beena
Ad

Similar to Do it in code! A guide to creating a custom site structure plugin in WordPress. (20)

PPTX
A Sneak Peek At Visual Studio 2010 And .Net Framework 4.0
PPT
.NET Debugging Tips and Techniques
PPT
.Net Debugging Techniques
PDF
AEM 6.X (With Basics) Training Syllabus
PPTX
Using advanced C# features in Sharepoint development
PPTX
Sps Boston The Share Point Beast
PDF
Building a single page application with Polymer
PPTX
Android 101 - Introduction to Android Development
PPT
Vs2005p
PPTX
Android crash course
PDF
Top 10 IDEs for React.js Developers in 2021
ODP
Wordpress as a CMS
PDF
Gerrit linuxtag2011
PDF
What's new in Portal and WCM 8.5
PPT
Monorail presentation at WebDevelopersCommunity, Feb 1, 2009
PPT
Develop a Quick and Dirty Web interface to your database: for the DBA and oth...
PPT
Hippo CMS - A first look
PPTX
Windows containers troubleshooting
DOCX
C# tutorial
PDF
Ad102 - Extreme Makeover -- LotusScript and Java Editor Edition
A Sneak Peek At Visual Studio 2010 And .Net Framework 4.0
.NET Debugging Tips and Techniques
.Net Debugging Techniques
AEM 6.X (With Basics) Training Syllabus
Using advanced C# features in Sharepoint development
Sps Boston The Share Point Beast
Building a single page application with Polymer
Android 101 - Introduction to Android Development
Vs2005p
Android crash course
Top 10 IDEs for React.js Developers in 2021
Wordpress as a CMS
Gerrit linuxtag2011
What's new in Portal and WCM 8.5
Monorail presentation at WebDevelopersCommunity, Feb 1, 2009
Develop a Quick and Dirty Web interface to your database: for the DBA and oth...
Hippo CMS - A first look
Windows containers troubleshooting
C# tutorial
Ad102 - Extreme Makeover -- LotusScript and Java Editor Edition
Ad

Recently uploaded (20)

PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Spectroscopy.pptx food analysis technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Cloud computing and distributed systems.
PDF
Approach and Philosophy of On baking technology
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Electronic commerce courselecture one. Pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Spectroscopy.pptx food analysis technology
“AI and Expert System Decision Support & Business Intelligence Systems”
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Spectral efficient network and resource selection model in 5G networks
Cloud computing and distributed systems.
Approach and Philosophy of On baking technology
Understanding_Digital_Forensics_Presentation.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
MIND Revenue Release Quarter 2 2025 Press Release
Network Security Unit 5.pdf for BCA BBA.
Unlocking AI with Model Context Protocol (MCP)
NewMind AI Weekly Chronicles - August'25 Week I
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Advanced methodologies resolving dimensionality complications for autism neur...
Building Integrated photovoltaic BIPV_UPV.pdf
Big Data Technologies - Introduction.pptx
Programs and apps: productivity, graphics, security and other tools
Electronic commerce courselecture one. Pdf

Do it in code! A guide to creating a custom site structure plugin in WordPress.

  • 1. 1 Do it in code! A guide to creating a custom site structure plugin in WordPress. Presented by: Peter Hebert Rex Rana Design and Development Ltd. Rex Rana
  • 2. 2 What is site structure? Post Types Metaboxes and Fields Taxonomy Menus Permalink Structure Rex Rana
  • 3. 3 Why a custom plugin? Functionality should live in code, not the database Themes for presentation, plugins for functionality Manage code in version control system (git, svn) Code Portability / Deployment dev / staging / production re-use for multiple websites / different clients
  • 4. 4 Our Sample Plugin We'll create a Film listing (like IMDB) Custom Post Type: Film Custom Taxonomy: Genre Metabox: Film Info Fields: Release Date, Duration, Director https://github.com/rexrana/my-custom-structure
  • 5. 5 WordPress core functionality Not easy to use — you have to do all the heavy li ing CRUD functions (create, read, update and delete) Callback functions with HTML to display fields in admin Sanitization / validation of input nonces It's a lot to remember — time could be better spent
  • 6. 6 Thankfully, there’s a better way! Many tools exist for simplifying the creation of site structure: Plugins (Advanced Custom Fields, Pods, etc.) Most have an export to code functionality Developer libraries: CMB2, Custom Meta Boxes Code Generators: GenerateWP, WP-CLI scaffold command
  • 7. 7 GUI-based structure plugins Create your structure in the admin, then export to code. export to XML (v4 and below), JSON (v5), PHP framework Migrate: Packages Pods Deploy - uses WordPress REST API (beta) / Packager Advanced Custom Fields Pods Toolset Embedded Toolset
  • 8. 8 Developer library: CMB2 github.com/WebDevStudios/CMB2 Toolkit for building metaboxes, custom fields, and forms Takes care of all the hard stuff for you Declare metaboxes and fields using arrays of parameters 32 field types included, with API to declare your own Use on Post Types, Options Pages, User Profiles even on the front end of your site
  • 9. 9 Developer library: Custom Meta Boxes github.com/humanmade/Custom-Meta-Boxes/ Framework for easily adding custom fields works similarly to CMB2 (parameter arrays) (seems to) only work on post edit pages fork of original CMB (predecessor to CMB2) 20 field types included, plus repeater field features a basic 12 column grid system to align fields
  • 10. 10 Code Generators: GenerateWP generatewp.com Form-based wizards for generating code compliant with WordPress coding standards Select a tool, fill in the form, generate the code Copy ready-to-use code directly to your plugin.
  • 11. 11 Code Generators: WP-CLI 'scaffold' wp-cli.org/commands/scaffold/ Command within WordPress command-line interface (CLI) Generates starter code for themes, plugins, unit tests, post types and taxonomy. Limited - cannot specify advanced parameters, only gives minimal config with defaults Provides a quick start-off point
  • 12. 12 WP-CLI Scaffolding Examples Run commands from within site directory 'Film' post type wp scaffold post­type film ­­label=Film ­­textdomain=structure  ­­dashicon=editor­video ­­plugin=my­custom­structure 'Genre' taxonomy wp scaffold taxonomy genre ­­post_types=film ­­label=Genre  ­­textdomain=structure ­­plugin=my­custom­structure
  • 13. 13 Putting it all together If using ACF or CMB2 : Install plugin in normal way, or: Download to a subdirectory, include in your plugin's main PHP file Create separate PHP files for each of: Post Types, Taxonomy, Metaboxes/Fields include these files in your main plugin PHP file this makes items easier to find, comment out or remove
  • 14. 14 Developer library includes Advanced Custom Fields if( file_exists( dirname(__FILE__).'/lib/advanced­custom­ fields/acf.php' ) ) { include_once( 'lib/advanced­custom­fields/acf.php' ); } CMB2 if( file_exists( dirname(__FILE__).'/lib/cmb2/init.php' ) ) {     include_once( 'lib/cmb2/init.php' ); }
  • 15. 15 Includes for declaring structure include_once('post­types/film.php'); include_once('taxonomies/genre.php'); // METABOXES AND FIELDS /* using WordPress core functionality */ include_once('inc/wp­fields.php'); /* using ACF */ include_once('inc/acf­fields.php'); /* using CMB2  */ include_once('inc/cmb2­metaboxes.php');
  • 16. 16 Resources CMB2: THE METABOX STRIKES BACK (Justin Sternberg) Plugin comparison - Custom Post Types / Fields (Google spreadsheet) Custom Post Type Permalinks (plugin) story w.com/cmb2-metabox-strikes-back goo.gl/o7kU9s wordpress.org/plugins/custom-post-type-permalinks/
  • 17. 17 Thank You Find me online: rexrana.ca peterhebert.com @RexRanaDesign @peter_hebert peterhebert rexrana