Dev log
Use WordPress functions outside WordPress, and the better options
Require wp-load.php to use WordPress functions in another PHP script. I also cover when SHORTINIT, the REST API or WP-CLI is the better tool.
5 min read
Field notes
Journal
Notes from the Riksi studio in Melbourne. Plain guides on WordPress, Shopify, front-end code, speed and the tools I use every day.
Dev log
Use WordPress functions outside WordPress, and the better options
Require wp-load.php to use WordPress functions in another PHP script. I also cover when SHORTINIT, the REST API or WP-CLI is the better tool.
5 min read
Dev log
Create and use a dynamic sidebar (widget area) in WordPress
Register a widget area with register_sidebar(), show it with dynamic_sidebar() inside is_active_sidebar(), and handle block widgets since WordPress 5.8.
4 min read
Dev log
Show one WordPress page’s content in another template
Pull one page's content into another template with get_post() and the_content filter, or setup_postdata() for template tags. I include a safe shortcode too.
4 min read
Dev log
Replace text in a string with JavaScript
replace() changes the first match. replaceAll() or a regex with the g flag changes every match. Also case-insensitive swaps, $ patterns and escaping input.
4 min read
Dev log
Remove or escape illegal characters in a MySQL string
There are two jobs here. Stop quotes breaking a query with prepared statements, and clean unwanted characters out of stored data with REPLACE, TRIM or REGEXP_REPLACE.
4 min read
Dev log
Run a WordPress shortcode from PHP (and when not to)
Use do_shortcode() to run a shortcode in a PHP template, or call the function behind it when the shortcode is yours. Plus timing, escaping and [embed].
5 min read