All WordPress snippets
Want your own copy?
Fork this repo and build your own snippet collection. Fork on GitHub →
WordPress
Standard Pattern for Enqueuing Theme CSS/JS
A template for loading Bootstrap plus your own stylesheet and script correctly through WordPress's enqueue system.
php
/**
* Enqueue styles and scripts
*/
function custom_scripts() {
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css', array(), '3.3.6' );
wp_enqueue_style( 'style', get_template_directory_uri() . '/css/style.css' );
wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), '3.3.6', true );
wp_enqueue_script( 'script', get_template_directory_uri() . '/js/script.js' );
}
add_action( 'wp_enqueue_scripts', 'custom_scripts' );
More WordPress snippets
Register and Output a Custom Nav Menu
Adds a new menu location you can assign in Appearance → Menus, shows how to output it in a template, and includes the multi-menu version too.
Define a Reusable Global String
A simple pattern for storing a value — like a phone number or address — in one place and reusing it anywhere in your theme.
Auto-Escape HTML Typed Inside Code Tags
Makes sure any markup typed inside <code> or <tt> tags in the editor gets escaped automatically, so it displays as visible text instead of being rendered as real HTML.