Skip to content

Instantly share code, notes, and snippets.

@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.
@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 / 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 / image-category-snippet.php
Last active January 3, 2016 16:09
Add categories to your WordPress Images
<?php
// Begin Copy into functions.php
function image_category() {
$labels = array(
'name' => 'Image Categories',
'singular_name' => 'Image Category',
'menu_name' => 'Image Categories',
'all_items' => 'All Image Categories',
'parent_item' => 'Parent Image Category',
#!/bin/sh
defaults write com.apple.finder CreateDesktop -bool false
killall Finder
osascript -e 'tell application "Terminal" to close (every window whose name contains ".command")' &
exit
<?php
/*
Copyright (c) 2012 Twilio, Inc.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
@infn8
infn8 / fn_var_pre.php
Last active August 29, 2015 14:02
Var Dump Helper Function and sublime caller snippet
<?php
function var_pre($var, $msg = NULL){
/*
Helper Function:
Use *instead of* var_dump();
will output var_dump wrapped with <pre></pre> and give an optional 2nd param for a message.
*/
echo "\n<pre>";
if($msg !== NULL){
echo "\n".$msg."\n";
@infn8
infn8 / .gitignore_global
Created July 10, 2014 21:21
Global gitignore
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@infn8
infn8 / Wp Permissions.txt
Last active August 29, 2015 14:04
Set WP permissions on Dreamhost via SSH
cd /path/to/wordpress/install/
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
find . -name "wp-config.php" -exec chmod 640 {} \;
@infn8
infn8 / output_comment.php
Created July 22, 2014 19:23
Toss this in all your WordPress template files to add a source code comment that helps you track down what file is generating your page.
<!-- Generating Template: <?php echo basename(__FILE__, '.php'); ?>.php -->