Skip to content

Instantly share code, notes, and snippets.

@infn8
infn8 / redirect.php
Last active December 29, 2015 16:19
301 Redirect template for wordpress
<?php
/*
Template Name: Redirect
*/
if(! empty($url = get_post_meta(get_the_id(), 'redirect', true))){
header("HTTP/1.1 301 Moved Permanently");
header("Location: ". $url);
die();
}
?>
@infn8
infn8 / Local Wordpress Buffer
Last active December 29, 2015 00:59
a method for deploying a dev site without having to update every reference to the new site. perfect for when your local dev is using a host file but you want to show your client some progress.For wordpress add this to wp-config.php at the top and edit the $old and $new variables for the domains you need to edit.
function ob_local_dev($buffer){
$old = "http://example.com";
$new = "http://dev.example.com";
return str_replace($old, $new, $buffer);
}
ob_start("ob_local_dev");
@infn8
infn8 / gist:5126011
Created March 9, 2013 22:19
Wordpress Style Slug Generator function in php
function generateSlug($phrase, $maxLength=50){
$result = strtolower($phrase);
$result = preg_replace("/[^a-z0-9]/", "-", $result);
$result = trim(preg_replace("/-+/", "-", $result));
$result = trim(substr($result, 0, $maxLength));
$result = preg_replace("/^-/", "", $result);
$result = preg_replace("/-$/", "", $result);
return $result;
}
// Pretty simple: keeps numbers and letters and makes everything else dashes. Removes multiple dashes in a row.