Code Snippets

WordPress Snippets

Hooks, filters, and getting out of the theme editor - shortcodes, functions.php snippets, and how to write them without opening a hole.

Search these 7 posts

Everything in WordPress Snippets

  • Diagram: the DISALLOW_FILE_EDIT constant cutting the line from a stolen admin password to the in-admin PHP file editor.

    11/16/2014

    Disable the WordPress theme and plugin file editor

    To tighten security of your WordPress site, you can disable users’ ability to edit your theme and plug-in files. After all, isn’t that what your web development team should be doing?

  • Diagram: the WordPress admin frame with Tasks, Milestones and Calendar panels added inside it, replacing a separate project-management app.

    08/06/2014

    CollabPress: project management inside WordPress

    Some people are so enamored with these shiny new project management tools that load so nicely on our smart phones that they forget it should be a transparent part of the project and not a task and part of the process of…

  • Diagram: one contact-form plugin branching into three separate forms, Sales, Support and Careers, each routed to its own address.

    03/16/2014

    Need multiple contact forms on your WordPress website?

    There are plenty of contact form plug-ins for WordPress. I’ve used a few that I thought would be good but turned out to be barely functional, clunky, and/or buggy.

  • Diagram: a shortcode with category and limit arguments feeding a list of post cards, each carrying a thumbnail and an excerpt.

    03/08/2014

    A WordPress shortcode that lists posts or pages

    In WordPress, you can do a lot with shortcodes, the problem is, some work fine then one day they just break. It’s best to stick with ones that work reliably, even when you upgrade.

  • Insert PHP Code in WordPress via Shortcode

    02/26/2014

    Including a PHP file from a WordPress shortcode, safely

    The 2014 version of this shortcode takes a file path out of the post and includes it, which is a local file inclusion hole with extra steps. The fix is small: let the code decide which files are includable, not the person writing the post.

  • Diagram: the three WordPress debug constants and the combination that is safe to leave on for a live site.

    02/26/2014

    Turn on WordPress Debugging

    When you’re in development mode, it’s useful to get errors in scripts as they occur. Just place this line anywhere in your functions.php file for your active child theme and you will start seeing debug feedback complete…

  • Diagram: the comment_form() call in comments.php replaced by one with an empty comment_notes_after, trimming the trailing markup it used to add.

    02/25/2014

    Remove the markup WordPress adds after a comment form

    Find the line in your child theme’s “comment.php” file where it calls on the function comment_form() and replace that line with this: