Skip to content

Instantly share code, notes, and snippets.

View jayseventwo's full-sized avatar

jayseventwo jayseventwo

View GitHub Profile
@jayseventwo
jayseventwo / wp-white-screen-of-death
Last active August 29, 2015 13:59
WP white screen of death
// add to wp-config.php to view errors if your WP install only shows a white page
error_reporting(E_ALL); ini_set('display_errors', 1);
define( 'WP_DEBUG', true);
@jayseventwo
jayseventwo / cat-class-to-body
Created June 4, 2014 00:55
Add category class to body in WordPress
// add category class to body
function body_class_add_categories( $classes ) {
// Only proceed if we're on a single post page
if ( !is_single() )
return $classes;
// Get the categories that are assigned to this post
$post_categories = get_the_category();
@jayseventwo
jayseventwo / gist:8b17ca7ffc8f2e725f18
Created September 4, 2014 21:35
Add popup prompt when pressing publish button in WP
/* = Add a "molly guard" to the publish button */
add_action( 'admin_print_footer_scripts', 'sr_publish_molly_guard' );
function sr_publish_molly_guard() {
echo <<<EOT
<script>
jQuery(document).ready(function($){
$('#publishing-action input[name="publish"]').click(function() {
if(confirm('Are you sure you want to publish this?')) {
return true;
@jayseventwo
jayseventwo / 404 to 301
Created September 23, 2014 22:41
404 error to 301 redirect
/* Redirect 404 to correct page */
add_filter( '404_template', 't5_redirect_to_category' );
function t5_redirect_to_category( $template )
{
if ( ! is_404() )
return $template;
global $wp_rewrite, $wp_query;
@jayseventwo
jayseventwo / cat-order
Created September 23, 2014 23:11
Stope categories going out of order in WP pages/posts admin
/* ----------------------------------- stop categories going out of order in WP page/poasts admin ---------------*/
function taxonomy_checklist_checked_ontop_filter ($args)
{
$args['checked_ontop'] = false;
return $args;
}
@jayseventwo
jayseventwo / add to head
Created September 25, 2014 01:34
Add custom code to head tag through function
add_action('wp_head', 'wpse_43672_wp_head');
function wpse_43672_wp_head(){
//Close PHP tags
?>
ADD YOUR PLAIN HTML CODE HERE
<?php //Open PHP tags
}
@jayseventwo
jayseventwo / shortcodes.php
Last active December 15, 2015 05:29
Add Bootstrap Twitter shortcodes dropdown to your page/post editor when using Roots Theme. Also adds shortcode ability to widgets. Add this custom.php.
/**
* --------------------------------------------------------------------------------------------------------------------------- Add shortcodes */
add_shortcode('row', 'j72_row' );
add_shortcode('span', 'j72_span' );
add_shortcode('span4', 'j72_span4' );
add_shortcode('span5', 'j72_span5' );
add_shortcode('span6', 'j72_span6' );
add_shortcode('well', 'j72_well' );
add_shortcode('button', 'j72_button');
@jayseventwo
jayseventwo / show-if-certain-category
Created April 24, 2013 03:49
Show/hide certain page elements depending on category (useful for custom post types).
<?php if ( 'portfolio' == get_post_type() ) { ?>
portfolio
<?php } else { ?>
blog
<?php } ?>
@jayseventwo
jayseventwo / Roots theme - hide page header on home page
Created April 24, 2013 03:50
open templates/page-header.php and replace with:
<?php if( !is_front_page() ):?>
<div class="page-header">
<h1><?php echo roots_title(); ?></h1>
</div>
<?php endif;?>
@jayseventwo
jayseventwo / Add custom menus to WordPress
Created April 24, 2013 03:52
Example code shown in lib/init.php for Roots theme or you can add to custom/functions.php
register_nav_menus(array(
'primary_navigation' => __('Primary Navigation', 'roots'),
'header-menu' => __( 'Header Menu' ) ,
'footer-menu' => __( 'Footer Menu' )
));