Skip to content

Instantly share code, notes, and snippets.

View mrbobbybryant's full-sized avatar

Bobby Bryant mrbobbybryant

View GitHub Profile
@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 / loadmore.js
Last active November 13, 2022 01:58
Example WordPress Rest API pagination abstraction
import queryString from 'query-string';
import { getSpinner } from './components';
/**
* Implementation Example at the very bottom.
*/
export default function( settings ) {
let page = 2;
let buttonContent;
let headers;
@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: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: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: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 / user-data.php
Created February 27, 2016 17:46
code snippet from the User Generated data video
<?php
function register_user_question_content_type() {
$post_labels = array(
'name' => 'User Questions',
'singular_name' => 'User Question',
'add_new' => 'Add New',
'add_new_item' => 'Add New User Question',
'edit' => 'Edit',
'edit_item' => 'Edit User Question',
'new_item' => 'New User Question',
@mrbobbybryant
mrbobbybryant / get-image.php
Created March 3, 2017 22:13
Get Custom Image
<?php
/**
* This function will return all the image data (id, url)
* @param $post_id int The post id.
* @param $name string the name of your custom field you used when creating the field.
*
* @return mixed
*/
function get_custom_upload( $post_id, $name ) {
@mrbobbybryant
mrbobbybryant / wp_code_context.php
Last active July 25, 2017 08:40
Allows you to dynamically determine if your code is being used in a plugin or a theme
<?php
function wp_code_context() {
$theme = strpos( __DIR__, 'themes' );
return ( $theme ) ? 'theme' : 'plugin';
}
function get_directory_by_context() {
$context = wp_code_context();
switch( $context ) {
case 'theme':
$local_dir = get_template_directory();
@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/'
) );