Skip to content

Instantly share code, notes, and snippets.

@bavington
bavington / wp_widget_plugin.php
Created July 29, 2013 18:51
Boilerplate for creating a simple Widget Plugin in Wordpress.
<?php
/*
Plugin Name: My Widget Plugin
Plugin URI: http://twitter.com/jamesbavington
Description: A simple plugin that adds a simple widget
Version: 0.1
Author: bavington
Author URI: http://twitter.com/jamesbavington
License: GPL2
*/
@bavington
bavington / wp_plugin_settings_link.php
Created August 19, 2013 12:56
Simple function that links up your settings page from the plugin overview page:
@bavington
bavington / 503.php
Created August 20, 2013 07:52
Declare a 503 Status via PHP for SEO friendly downtime.
<?php
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Retry-After: Sat, 8 Oct 2011 18:27:00 GMT'); //How long before you estimate your website will be back.
?>
<!DOCTYPE HTML>
<html>
<head>
@bavington
bavington / holding_page_htaccess
Created August 20, 2013 07:54
Redirect all of your server's traffic to a single holding page by .htaccess.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/offline\.php$
RewriteRule ^(.*)$ /offline.php [L]
@bavington
bavington / logo_schema.html
Last active December 21, 2015 10:19
Optimise your website's logo with Google's logo Schema Mark up.
<div itemscope itemtype="http://schema.org/Organization">
<a itemprop="url" href="http://www.yourdomain.co.uk/">
<img itemprop="logo" src="http://www.yourdomain.co.uk/logo.png" alt="Company Name ALT Text" />
</a>
</div>
@bavington
bavington / wp_basic_shortcode.php
Last active December 23, 2015 20:19
Basic Wordpress Shortcode registry and callback function.
<?php
function last_updated_code() {
return "<p>This post was last edited on ".get_the_modified_date()." by ".get_the_modified_author()."</p>";
}
add_shortcode( 'lastupdated', 'last_updated_code' );
?>
@bavington
bavington / retina-media-query.css
Created November 20, 2013 19:57
Retina Detection Media Query for working with Retina Background Images.
div.logo {
margin:0 auto;
border:1px solid #666;
width:400px;
height:215px;
background:url(james-n-nick.jpg) no-repeat;
}
@media only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and (-webkit-min-device-pixel-ratio: 1.5),
@bavington
bavington / LocalBusinessSchema.html
Last active December 30, 2015 06:28
Boilerplate for LocalBusiness Schema.org Markup
<div itemscope itemtype="http://schema.org/LocalBusiness">
<span itemprop="legalName">Company Name Ltd</span>
<div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
<span itemprop="streetAddress">12 Paper Street,</span>
<span itemprop="addressLocality">Town</span>,
<span itemprop="addressRegion">County</span>
<span itemprop="postalCode">AB01 1YZ</span>
</div>
Phone: <span itemprop="telephone">01234 123456</span>
Email: <span itemprop="email">email@companydomain.co.uk</span>
@bavington
bavington / custom-post-type.php
Created January 2, 2014 19:39
Custom Post Type and initial taxonomy boilerplate
<?php
///////////////////////////////////////////////
////////// Projects Custom Post Type //////////
///////////////////////////////////////////////
add_action('init', 'register_projects');
function register_projects() {
@bavington
bavington / wp-custom-post-type-class-fix.php
Created January 5, 2014 11:13
Fixes the problems (post WordPress 3.1) with Custom Post Type Menu classes not being added correctly.
<?php function remove_parent_classes($class)
{
// check for current page classes, return false if they exist.
return ($class == 'current_page_item' || $class == 'current_page_parent' || $class == 'current_page_ancestor' || $class == 'current-menu-item') ? FALSE : TRUE;
}
function add_class_to_wp_nav_menu($classes)
{
switch (get_post_type())
{