Writing a Clean WordPress Shortcode
Shortcodes are old, but they are still the simplest way to give writers a reusable block in the classic editor.
Most of the improvement in a draft comes from cutting. We aim to remove a fifth of every piece on the second pass, and the reader never misses it.
shortcode-note.php
function quill_note_shortcode( $atts, $content = '' ) {
$atts = shortcode_atts( array( 'type' => 'info' ), $atts, 'note' );
ob_start();
?>
<aside class="note note--<?php echo esc_attr( $atts['type'] ); ?>">
<?php echo wp_kses_post( $content ); ?>
</aside>
<?php
return ob_get_clean();
}
add_shortcode( 'note', 'quill_note_shortcode' );
PHP
Taking notes by hand is slower, and that is the point. The friction forces you to decide what matters before you write it down.
Reading work aloud is the cheapest editing tool there is. Your ear catches rhythm problems that your eye skips over, especially in long sentences.
Continue reading
Related posts
Shell Aliases That Save Us an Hour a Week
Git, rsync, and image tools, shortened to a few keystrokes.
A Small Go Server for Static Previews
Serve a folder, add caching headers, and ship a single binary.
Parsing Markdown Front Matter in Python
Split, parse, and validate the YAML block at the top of a file.
Comments · 4
Do you have a recommendation for someone just starting out? Everything I find assumes years of experience.
Such a clear explanation. I finally understand why our pages felt sluggish on mobile.
Glad it helped. The second pass is where it really clicks.
Small typo in the third paragraph, but otherwise a perfect read with my morning coffee.