Skip to content

Instantly share code, notes, and snippets.

View mrbobbybryant's full-sized avatar

Bobby Bryant mrbobbybryant

View GitHub Profile
@mrbobbybryant
mrbobbybryant / gist:e28efc0d84afbead7d0e
Last active June 8, 2017 09:17
WordPress Custom Post Type (Simple)
<?php
function dwwp_register_post_type() {
$args = array('public'=> true, 'label'=> 'Staff');
register_post_type( 'staff', $args);
}
add_action( 'init', 'dwwp_register_post_type' );
@mrbobbybryant
mrbobbybryant / gist:83c4a076da6dd67de3da
Created November 19, 2014 20:30
Properly enqueue bootstrap into WordPress
<?php
/**
* Enqueue scripts and styles
*/
function your_theme_enqueue_scripts() {
// all styles
wp_enqueue_style( 'bootstrap', get_stylesheet_directory_uri() . '/css/bootstrap.css', array(), 20141119 );
wp_enqueue_style( 'theme-style', get_stylesheet_directory_uri() . '/css/style.css', array(), 20141119 );
// all scripts
wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), '20120206', true );
@mrbobbybryant
mrbobbybryant / gist:3f5ec4f224ad8ca8cd06
Last active July 25, 2017 08:39
Adding a Google Analytics Link to the Wordpress Dashboard
<?php
function dwwp_add_google_link() {
global $wp_admin_bar;
$wp_admin_bar->add_menu( array(
'id' => 'google_analytics',
'title' => 'Google Analytics',
'href' => 'http://google.com/analytics/'
) );
@mrbobbybryant
mrbobbybryant / gist:f1714ab93b8171947ed7
Last active January 5, 2018 20:42
WordPress Custom Post Type (Using $singular and $plural)
<?php
//Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
function dwwp_register_post_type() {
$singular = 'Job';
$plural = 'Jobs';
@mrbobbybryant
mrbobbybryant / gist:79ef228f46de5097802d
Last active February 23, 2018 10:56
Introduction to WordPress Filters
<?php
// Define our Custom Post Type
function dwwp_register_post_type() {
//Add a filter to our $singular variable.
$singular = apply_filters( 'dwwp_label_single', 'Book' );
//Add a filter to our $plural variable.
$plural = apply_filters( 'dwwp_label_plural', 'Books' );
$labels = array(
@mrbobbybryant
mrbobbybryant / gist:3746a9fa5bf0e02d6363
Created January 4, 2015 20:40
Removing Dashboard Widgets
<?php
function dwwp_remove_dashboard_widgets() {
remove_meta_box( 'dashboard_primary', 'dashboard', 'post_container_1' );
}
add_action( 'wp_dashboard_setup', 'dwwp_remove_dashboard_widgets' );
@mrbobbybryant
mrbobbybryant / gist:fdb76c7129370062956f
Last active February 10, 2018 13:00
How to Create a Custom WordPress Taxonomy
<?php
function dwwp_register_taxonomy() {
$singular = 'Location';
$plural = 'Locations';
$slug = str_replace( ' ', '_', strtolower( $singular ) );
$labels = array(
'name' => $plural,
@mrbobbybryant
mrbobbybryant / gist:327d90be32c3c3e4b0fd
Created January 20, 2015 18:10
Properly including external files into a WordPress plugin
<?php
require_once ( plugin_dir_path(__FILE__) . 'wp-job-cpt.php' );
<?php
function dwwp_add_custom_meta() {
add_meta_box(
'dwwp_meta',
'Job Listing',
'dwwp_meta_callback',
'job',
'side',
'core'
@mrbobbybryant
mrbobbybryant / gist:742dd80725c95da96b57
Last active August 29, 2015 14:14
Change the default WordPress title placeholder text
<?php
//If you only need to change one use this version.
function dwwp_change_title( $title_placeholder) {
$screen = get_current_screen();
if ( $screen->post_type == 'job' ) { //<--Your post type name goes here.
$title_placeholder = 'I changed the title yo';