Skip to content

Instantly share code, notes, and snippets.

@bavington
bavington / outside-the-loop.php
Last active January 6, 2021 06:57
How to access the Loop and display your posts, from outside of Wordpress.
<ul>
<?php
require($_SERVER['DOCUMENT_ROOT'] . '/wordpress/wp-load.php');
$args = array(
// 'cat' => 3, // Only source posts from a specific category
'posts_per_page' => 2 // Specify how many posts you'd like to display
);
$latest_posts = new WP_Query( $args );
if ( $latest_posts->have_posts() ) {
while ( $latest_posts->have_posts() ) {
@bavington
bavington / Full Domain 301 .htaccess
Last active July 22, 2020 15:05
.htaccess rewrite code to use when 301'ing to a new domain name whilst maintaining the same URL paths.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.newdomain\.co.uk
RewriteRule (.*) http://www.newdomain.co.uk/$1 [R=301,L]
@bavington
bavington / Telephone Touch Event Tracking .html
Last active February 6, 2018 12:22
Simple telephone touch/click Event Tracking for Google Analytics.
<a href="tel:0800123456" onclick="_gaq.push(['_trackEvent','Phone Call Tracking','Click/Touch','Footer']);">
0800123456
</a>
@bavington
bavington / google-map-api.html
Last active August 3, 2019 17:37
Simple, custom Google Map (API 3.0)
<!doctype html>
<html>
<head>
<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=false"></script>
<meta charset="UTF-8">
<title>Example Google Map</title>
</head>
<body>
<div id="map-canvas" style="height:400px; width:600px;"></div>
<script>
@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' );
?>