I replicated wordpress.org’s code reference system for my own project.
WordPress provides a template tag get_the_title()
and it’s documented at https://developer.wordpress.org/reference/functions/get_the_title/.
A plugin I just launched provides a template tag invp_get_the_price()
and it’s documented at https://inventorypresser.com/docs/reference/functions/invp_get_the_price/
I learned that the .org docs page content is generated by scanning the project source code, extracting PHPDoc comments, and parsing them into custom post types. The piece of software that does that is https://github.com/WordPress/phpdoc-parser.
Build the Data
- Add PHPDoc comments to all classes and methods in your plugin.
- Use a server that provides the WordPress Command Line Interface.
- Upload your plugin to the site where you want to generate documentation.
- Activate the phpdoc-parser plugin on the same site
- Connect via SSH and run a wp-cli command similar to
wp parser create ../../sites/inventorypress/wp-content/plugins/inventory-presser/ --user=corey
- Replace the path with a path to the plugin for which you want documentation.
- Change the user name to the name of an administrator on your site.
Build the Theme
WordPress.org uses a handful of themes at once. The developer reference pieces live in the wporg-developer theme.
Take Files from wporg-developer
This SVN command will download the whole theme. Paste the command into a terminal or command prompt window:
svn co https://meta.svn.wordpress.org/sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/
Copy these files from wporg-developer into your child theme
- /inc
- /js
- /reference
- /stylesheets
- content-reference.php
- content-reference-archive.php
- functions.php (comingle it with your functions.php)
Theme Mods
- Change option value
wp_parser_root_import_dir
to contain a path to the project. For me, this path points to a plugin in thewp-content/plugins
folder. - Change
get_template_directory_uri()
calls toget_stylesheet_directory_uri()
calls - Create single.php by taking a copy from the parent theme. Modify it to serve a different content template for the post types populated by phpdoc-parser. Here is a code sample that shows what to change to create a Twenty Twenty-One child theme.
- Optional: Change “View on Trac” links
I added two filters that wrap the URL and the text in the “View on Trac” link below the source code section of each page. These changes allow me to change the links to “View on Github” or wherever I want.wp-parser_source_url_base
line 1173 of template-tags.phpwp-parser_view_on_trac_link_text
in a few places in template-source.php
Twenty Twenty-One Child Theme
Download a Twenty Twenty-One child theme with the files listed and mods 1-3 completed: https://github.com/csalzano/twentytwentyone-wporg-child
Twenty Twenty Four Child Theme
In early 2024, I redesigned inventorypresser.com using a Twenty Twenty Four child theme. I followed my own instructions in this post. I’ve published the child theme for anyone to use at https://github.com/fridaysystems/exteriordoor
Also Run These Plugins
- Handbook By WordPress.org
- Handbook Functionality for Pages By Nacin
- SyntaxHighlighter Evolved styles the source code editors.
- WP Parser creates the content in the Build the Data step above.
- WP Parser – Deleter By me, Corey Salzano. keeps track of every post created or updated by phpdoc-parser. Deletes untouched posts and empty taxonomy terms after wp-parser runs.
- WP Parser – Vendor Folder Ignorer By me, Corey Salzano. Instructs phpdoc-parser to ignore the /vendor folder
Troubleshooting
Missing Source Code
If no source code is displaying, edit the option wp_parser_root_import_dir
to contain a full path to the directory of the plugin. Example: /corey/sites/inventorypress/wp-content/plugins/inventory-presser
Automating Updates to Docs
When I wrote this post in 2021, the site I built this for was hosted at WP Engine. I no longer use this Github Action:
I wrote a Github Action to automate the creation and updating of the docs pages. When I push to the master branch of my plugin’s repo, the plugin is deployed to the site on WP Engine where the docs pages are hosted, and the wp-cli command that generates the docs is run.
Here is the workflow file that defines the Action at Github: https://github.com/fridaysystems/inventory-presser/blob/master/.github/workflows/main.yml
It contains one job with two steps that are marked with these comments: