Skip to content

Instantly share code, notes, and snippets.

View developdaly's full-sized avatar

Patrick Daly developdaly

View GitHub Profile
@developdaly
developdaly / functions.php
Last active August 29, 2015 14:01
This code will force HTTPS in the canonical URL meta tag of a WordPress site in an instance where SSL is not the forced protocol.
<?php
add_action( 'after_setup_theme', 'my_theme_setup' );
function my_theme_setup() {
/* Customize the canonical URL. */
remove_filter( 'wp_head', 'rel_canonical' );
add_filter( 'wp_head', 'my_rel_canonical' );
}
@developdaly
developdaly / force-ssl.php
Last active August 29, 2015 14:01
This snippet will check the current URL's protocol and if it matches http:// then it will redirect to the same URL but replace the protocol with https://
<?php
add_action( 'after_setup_theme', 'my_plugin_force_ssl' );
/**
* Force unencrypted URLs to redirect to an SSL encrypted version.
*/
function my_plugin_force_ssl() {
$protocol = stripos( $_SERVER['SERVER_PROTOCOL'],'https' ) === true ? 'https://' : 'http://';
if( $protocol == 'http://' ) {
@developdaly
developdaly / get_beanstalk_revision.php
Created November 28, 2012 03:25
This function gets the latest Beanstalk SVN/Git revision number for use in your theme/plugin
<?php
/**
* This function looks for the directory that "wp-config.php" resides in
* and then looks for a file named ".revision", the content of which is a
* single integer set by Beanstalk upon deployment.
*
* The purpose is to version static resources so that browsers will
* re-download any cached, outdated versions with the newer version.
*
@developdaly
developdaly / sunrise.php
Created December 3, 2012 13:22
WordPress network sunrise.php for multiple environments with a single database
<?php
// Check the current host or server name
if (isset($_SERVER['HTTP_HOST'])) {
$host = $_SERVER['HTTP_HOST'];
} elseif (isset($_SERVER['SERVER_NAME'])) {
$host = $_SERVER['SERVER_NAME'];
}
// Switch the host to the desired domain
$(document).ready(function () {
getRate( 'Dealer: New', 72, 72, '.rate-new-72-72' );
});
/**
* Retrieves the interest rate for given minimum and maximum month terms.
*
* @arg type string Required. The description of the product.
@developdaly
developdaly / media_shortcode.php
Last active March 16, 2016 21:45
This shortcode will reference a media item, configurable via attributes. Using a shortcode is more flexible and won't require database search/replace when migrating domains. Core would benefit from utilizing this system rather than inserting absolute paths to media URLs. A shortcode would keep media references relative to the site's domain.
<?php
/*
* Plugin Name: Media Shortcode
* Author: developdaly
* Version: 1.0
* Description: This shortcode will reference a media item, configurable via attributes. Using a shortcode is more flexible and won't require database search/replace when migrating domains.
*
* ex. [media id="97"] = <img src="http://example.com/97-300x150.jpg" class="thumbnail">
*
*/