Skip to content

Instantly share code, notes, and snippets.

View braginteractive's full-sized avatar

Brad Williams braginteractive

View GitHub Profile
@braginteractive
braginteractive / bootstrap-wordpress-contact-form.php
Created September 9, 2015 23:56
Contact Form WordPress page template with Bootstrap 3 classes
<?php
/**
* Template Name: Contact Page
*
* This is the template that displays a contact form.
*
* @package themename
*/
if(isset($_POST['submitted'])) {
<?php
// Get the Category
$id = get_the_id();
$terms = get_the_terms( $id, 'inventory_category' );
$firstcat = $terms[0]->name;
?>
@braginteractive
braginteractive / category-select.php
Last active July 29, 2016 23:21
Select box with a categories from a custom post type. Used for filtering posts.
<div class="filter">
<h5>Sort: </h5>
<?php
$cat_args = array(
'taxonomy' => 'inventory_category',
'parent' => 0,
'number' => 10,
'hide_empty' => true
);
$terms = get_terms($cat_args);
@braginteractive
braginteractive / parent-categories.php
Created July 30, 2016 02:32
Just display the parent categories of a CPT taxonomy
$taxonomy = 'inventory_category';
$cat_args = array(
'taxonomy' => 'inventory_category',
'parent' => 0,
'number' => 10,
'hide_empty' => true
);
$terms = get_terms($cat_args);
@braginteractive
braginteractive / functions.php
Last active April 7, 2017 05:14
Add Custom Logo Support to WordPress Theme
/*
* Add custom logo support
*/
add_theme_support( 'custom-logo' );
@braginteractive
braginteractive / extras.php
Created April 7, 2017 05:24
WordPress Filter to change the Custom Logo class
/**
* Changes the class on the custom logo in the header.php
*/
function helpwp_custom_logo_output( $html ) {
$html = str_replace('custom-logo-link', 'navbar-brand', $html );
return $html;
}
add_filter('get_custom_logo', 'helpwp_custom_logo_output', 10);
@braginteractive
braginteractive / content-cards.php
Created April 11, 2017 17:04
Add Featured Image to WordPress theme.
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'full', array('class' => 'card-img-top')); ?>
</a>
@braginteractive
braginteractive / example-meta-box.php
Created April 11, 2017 17:20
CMB2 example meta boxes
add_action( 'cmb2_admin_init', 'cmb2_sample_metaboxes' );
/**
* Define the metabox and field configurations.
*/
function cmb2_sample_metaboxes() {
// Start with an underscore to hide fields from custom fields list
$prefix = '_yourprefix_';
/**
@braginteractive
braginteractive / functions.php
Created April 11, 2017 17:24
Call meta-boxes.php file
/**
* Meta Boxes.
*/
require get_template_directory() . '/inc/meta-boxes.php';
@braginteractive
braginteractive / content-page.php
Created April 11, 2017 17:31
Display sample meta boxes on page
<?php
$text = get_post_meta( get_the_ID(), '_yourprefix_text', true );
$email = get_post_meta( get_the_ID(), '_yourprefix_email', true );
$url = get_post_meta( get_the_ID(), '_yourprefix_url', true );
echo esc_html( $text );
echo is_email( $email );
echo esc_url( $url );
?>