Skip to content

Instantly share code, notes, and snippets.

View designbuildtest's full-sized avatar

designbuildtest

View GitHub Profile
@designbuildtest
designbuildtest / gist:cb48bf5b32d362baaf46
Created February 17, 2015 03:41
Exclude Homepage from main Admin query
function exclude_this_page( $query ) {
if( ! is_admin() )
return $query;
global $pagenow;
if( 'edit.php' == $pagenow && ( get_query_var( 'post_type' ) && 'page' == get_query_var( 'post_type' ) ) )
$query->set( 'post__not_in', array(2) ); // Change '2' to the ID of your Homepage
return $query;
}
@designbuildtest
designbuildtest / gist:591eb6e3d3cc3364fac7
Created February 17, 2015 03:38
Prevent Homepage from being deleted
function myplugin_remove_homepage_delete($allcaps, $cap, $args) {
if ( ! is_super_admin() ) {
if ( 'delete_post' == $args[0] ) {
if ( get_option( 'page_on_front' ) == $args[2] ) {
$allcaps[$cap[0]] = false;
}
}
return $allcaps;
}
@designbuildtest
designbuildtest / gist:d3b4723f6f98179e7018
Created February 17, 2015 03:17
Remove ATTRIBUTES and EXCERPT meta boxes when viewing the Homepage.
function myplugin_remove_homepage_metaboxes() {
if ( isset( $_GET['post'] ) ) {
$post_id = $_GET['post'];
} elseif ( isset( $_POST['post_ID'] ) ) {
$post_id = $_POST['post_ID'];
}
$front_page = get_option( 'page_on_front' );
if ( ! isset( $post_id ) ) {
@designbuildtest
designbuildtest / gist:be3cbbaeeb66e98a97cb
Created February 17, 2015 02:10
Exclude a Metabox when Page is nominated as page_on_front
function myplugin_include_in_menu_meta_box() {
// Assign the ID of the page we're attempting to edit to a variable.
if ( isset( $_GET['post'] ) ) { $post_id = $_GET['post']; }
elseif ( isset( $_POST['post_ID'] ) ) { $post_id = $_POST['post_ID']; }
// Display metabox if we're creating a new page or editing a page other than the Homepage.
$front_page = get_option('page_on_front');
if ( ! isset($post_id) || ($post_id != $front_page) ) {
add_meta_box( 'myplugin_include_in_menu', __( 'Include in Navigation' ), 'myplugin_include_in_menu_meta_box_callback', 'page', 'side', 'default' );
}
@designbuildtest
designbuildtest / gist:10f89d2e0a354918e151
Created February 17, 2015 01:37
CPT Orberby Manage Column
function myplugin_custom_manage_affiliation_columns( $columns ) {
unset( $columns['author'] );
unset( $columns['date'] );
$columns['menu_order_affiliation'] = __( 'Order' );
return $columns;
}
add_filter( 'manage_edit-affiliation_columns', 'myplugin_custom_manage_affiliation_columns' );
@designbuildtest
designbuildtest / gist:c9174781cc755ac082ef
Created February 17, 2015 01:29
Page Orderby Manage Screen Column
$columns['menu_order'] = __( 'Order' );
case 'menu_order':
$order = $post->menu_order;
$ancestors = array_reverse( get_post_ancestors( $post->ID ) );
$value = get_post_meta( $post->ID, '_myplugin_include_in_menu', true );
@designbuildtest
designbuildtest / gist:253114936af7baa06491
Created February 17, 2015 01:26
Timely - Click to Call
if ( current_theme_supports( 'onehundred-call-to-action' ) ) {
function myplugin_call_to_action_customize_register($wp_customize) {
$wp_customize->add_section('call_to_action', array(
'title' => __('Call to Action Button', 'onehundred'),
'priority' => 25,
) );
$wp_customize->add_setting('myplugin_call_to_action_text', array(
@designbuildtest
designbuildtest / gist:222a0ae5194a1583c0ee
Created February 17, 2015 01:22
single-testimonial.php
<?php get_header(); ?>
<?php if ( have_posts() ) : ?>
<div class="container none-page-content testimonials">
<h1 class="capitalize"><?php echo get_post_type(); ?></h1>
<?php while ( have_posts() ) : the_post(); ?>
<blockquote>
@designbuildtest
designbuildtest / gist:7d30f953fec0929b4f14
Created February 17, 2015 01:21
archive-testimonial.php
<?php get_header(); ?>
<?php if ( have_posts() ) : ?>
<div class="container none-page-content testimonials">
<h1><?php post_type_archive_title(); ?></h1>
<?php while ( have_posts() ) : the_post(); ?>
<blockquote>
// Register 'Testimonial' Custom Post Type
function myplugin_testimonial_post_type() {
$labels = array(
'name' => _x( 'Testimonials', 'Post Type General Name' ),
'singular_name' => _x( 'Testimonial', 'Post Type Singular Name' ),
'menu_name' => __( 'Testimonials' ),
'add_new_item' => __( 'Add New Testimonial' ),
'search_items' => __( 'Search Testimonials' ),
);