Skip to content

Instantly share code, notes, and snippets.

View BeardedGinger's full-sized avatar

Josh Mallard BeardedGinger

View GitHub Profile
@BeardedGinger
BeardedGinger / Meta box only on published post
Last active August 29, 2015 14:04
Only display meta box on a published posts edit screen.
public function add_meta_box() {
global $pagenow;
if( in_array( $pagenow, array( 'post.php' ) ) ) {
// Display only if post is published
add_meta_box(
);
}
}
@BeardedGinger
BeardedGinger / is_child conditional
Created January 22, 2014 03:56
A simple function that allows you to conditionally check whether or not a page is a child page
<?php
function is_child( $page_id ) {
$child_check = get_post_ancestors( $page_id );
if($child_check) {
return true;
}
}
@BeardedGinger
BeardedGinger / Set WooCommerce Front-End Styles
Created December 23, 2013 03:31
Set front-end styles for WooCommerce on theme activation
//* Set the default WooCommerce front-end styles
global $pagenow;
if ( is_admin() && isset( $_GET['activated'] ) && $pagenow == 'themes.php' ) {
add_action( 'admin_init', 'woocommerce_default_frontend_styles' );
}
/**
* Define default WooCommerce frontend styles
*/
@BeardedGinger
BeardedGinger / Logged-in user template
Created December 21, 2013 05:09
Get different templates based on whether or not the visitor is logged in
if ( is_user_logged_in() ) {
get_template_part( 'home', 'loggedin' );
} else {
get_template_part( 'home', 'notloggedin' );
}
@BeardedGinger
BeardedGinger / gist:7879412
Created December 9, 2013 19:36
Check if the post has content - WordPress
<?php
//* Check if the post has content
if ($post->post_content == '') {
//* Content if post is empty
}
//* Alternate
if (get_post()->post_content == '') {
//* Content if post is empty
@BeardedGinger
BeardedGinger / Attachment slider in Template
Created October 14, 2013 20:56
Add the Exodus Attachment Slider to the template file of your choice
<?php
/*
* The page you would like to display the slider. This can be a page template or a single-{post-type}.php template
* Must be a page that you can attach images to.
*
*/
//* Enqueue the scripts for this page only
add_action( 'wp_enqueue_scripts', 'exodus_attachment_slider_scripts' );
@BeardedGinger
BeardedGinger / Attachment Slider
Created October 14, 2013 20:40
Add theme support for the attachment slider within the Exodus Framework
<?php
//* Add support for the Attachment Slider
add_theme_support( 'attachment-slider', 'defined_image_size' );
@BeardedGinger
BeardedGinger / Register Link Filter
Last active December 24, 2015 18:39
Filter for the "Register" link on WordPress login screen
@BeardedGinger
BeardedGinger / Checkbox User Roles
Created September 25, 2013 02:41
Get available WordPress user roles as checkboxes
<?php
global $wp_roles;
if ( ! isset( $wp_roles ) )
$wp_roles = new WP_Roles();
$roles = $wp_roles->get_names();
foreach ($roles as $role_value => $role_name) {
echo '<p><input type="checkbox" value="' . $role_value . '">'.$role_name.'</p>';
@BeardedGinger
BeardedGinger / declare WooCommerce support
Created September 25, 2013 02:21
Declare WooCommerce support
//* Declare WooCommerce Support
add_theme_support( 'woocommerce' );