Time to Start Using WordPress Code Snippets

Learn how to use copy & paste PHP Code Snippets to enhance your website

WordPress PHP Code Snippets
WordPress PHP Code Snippets

Code Snippets to the Rescue

Using PHP code snippets is an easy and safe way to get WordPress to do just about anything you want it do - except cook your dinner, but we've got a few developers working on it 😉.

WordPress code snippets are a "what you see is what you get" solution. Simply search for what you want executed. Googling something like "Rename uploaded files in WordPress" will typically direct you to a StackExchange thread, a Gist on Github, or an article like this one from WordPress Guru Jeff Starr.

Adding Snippets to WordPress

Adding PHP code snippets to your website is pretty straight forward. You can either add snippets to the functions.php file. Or you can use a popular plugin like Code Snippets. Using it makes adding and modifying your snippets much easier. It also offers a number of features you will feel quite familiar with as a WordPress user, such as: cloning, export, tagging, descriptions.

Code Snippets - WordPress Plugin
Code Snippets - WordPress Plugin

Here's a sample snippet to get you started. You can use it to bypass the default WordPress login page and go directly to your post list page.

WordPress Dashboard Redirect Snippet

// Redirect WordPress Dashboard to Another Page

add_action('load-index.php', 'dashboard_redirect');
function dashboard_redirect(){
wp_redirect(admin_url('/edit.php')); // change to desired page - include slash
  exit();
}

Perhaps you want to start on a custom post type list or your media library - no worries. Simply change the redirect page clearly labeled in the code.

We hope you found this tutorial useful and will try using WordPress code snippets. Be warned, using them can be addictive - just kidding. Let us know if and how you use code snippets. Until next time - #KeepPressing forward.

Last Updated: Sep 23, 2020
Was this helpful?
YesNo