Skip to content

Instantly share code, notes, and snippets.

View ekka21's full-sized avatar

Ekkachai Danwanichakul ekka21

View GitHub Profile
@ekka21
ekka21 / Wordpress Add a rel="nofollow" to the comment reply links
Created July 4, 2012 02:36
Wordpress: Add nofollow to the comment reply links
@ekka21
ekka21 / Get lat and lng from google map api
Created July 5, 2012 13:39
Get lat and lng from google map api
<?php
function getLatandLong($addr,$city,$state)
{
global $lat;
global $lng;
$doc = new DOMDocument();
$doc->load("http://maps.google.com/maps/api/geocode/xml?address=".$addr.",+".$city.",+".$state."&sensor=false"); //input address
//traverse the nodes to get to latitude and longitude
@ekka21
ekka21 / gist:3058240
Created July 6, 2012 05:12
Wordpress: set default thumbnail if NULL
add_action( 'save_post', 'wptuts_save_thumbnail' );
function wptuts_save_thumbnail( $post_id ) {
// Get Thumbnail
$post_thumbnail = get_post_meta( $post_id, $key = '_thumbnail_id', $single = true );
// Verify that post is not a revision
if ( !wp_is_post_revision( $post_id ) ) {
// Check if Thumbnail exists
@ekka21
ekka21 / gist:3066659
Created July 7, 2012 14:27
Wordpress: Add Extra Media Type Filters to the WordPress Media Manager
function modify_post_mime_types( $post_mime_types ) {
// select the mime type, here: 'application/pdf'
// then we define an array with the label values
$post_mime_types['application/pdf'] = array( __( 'PDFs' ), __( 'Manage PDFs' ), _n_noop( 'PDF <span class="count">(%s)</span>', 'PDFs <span class="count">(%s)</span>' ) );
// then we return the $post_mime_types variable
return $post_mime_types;
@ekka21
ekka21 / gist:3067107
Created July 7, 2012 16:30
Wordpress: remove post meta box
if (is_admin()) :
function my_remove_meta_boxes() {
if(!current_user_can('administrator')) {
remove_meta_box('linktargetdiv', 'link', 'normal');
remove_meta_box('linkxfndiv', 'link', 'normal');
remove_meta_box('linkadvanceddiv', 'link', 'normal');
remove_meta_box('postexcerpt', 'post', 'normal');
remove_meta_box('trackbacksdiv', 'post', 'normal');
remove_meta_box('commentstatusdiv', 'post', 'normal');
remove_meta_box('postcustom', 'post', 'normal');
@ekka21
ekka21 / gist:3071741
Created July 8, 2012 16:48
php: sanitize string
/**
* Function: sanitize
* Returns a sanitized string
*
* Parameters:
* $string - The string to sanitize.
* $force_lowercase - Force the string to lowercase?
* $anal - If set to *true*, will remove all non-alphanumeric characters.
*/
function sanitize($string, $force_lowercase = true, $anal = false) {
@ekka21
ekka21 / gist:3077354
Created July 9, 2012 16:05
Linux: .htaccess Redirect
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} domain.com
RewriteRule (.*)$ http://newdomain.com/$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteRule ^css/(.*) /wp-content/themes/roots/css/$1 [QSA,L]
RewriteRule ^js/(.*) /wp-content/themes/roots/js/$1 [QSA,L]
RewriteRule ^img/(.*) /wp-content/themes/roots/img/$1 [QSA,L]
@ekka21
ekka21 / Wordpress get thumbnail image src
Created July 11, 2012 21:51
Wordpress: get thumbnail image src
/**
* Desc: Get image source from feature image
* @param $id
* @param $icon = 'thumbnail, medium, large or full'
* @return $image source
*/
function get_me_the_thumbnail_src($id , $size = 'full'){
$tmp = wp_get_attachment_image_src ( get_post_thumbnail_id ( $id ), $icon ) ;
$str = $tmp[0];
return $str;
@ekka21
ekka21 / gist:3095710
Created July 12, 2012 04:23
Wordpress: load image automatically
<?php
//set images directory
$directory = 'wp-content/themes/mizzou/images/banners/';
try {
// create slideshow div to be manipulated by the above jquery function
echo "<div id=\"slideshow\">";
//iterate through the directory, get images, set the path and echo them in img tags.
foreach ( new DirectoryIterator($directory) as $item ) {
if ($item->isFile()) {
$path = $directory . "/" . $item;
@ekka21
ekka21 / gist:3098656
Last active October 7, 2015 03:28
php: states array
$states = array(''=>"STATE",'AL'=>"Alabama",'AK'=>"Alaska",'AZ'=>"Arizona",'AR'=>"Arkansas", 'CA'=>"California", 'CO'=>"Colorado", 'CT'=>"Connecticut", 'DE'=>"Delaware", 'DC'=>"District Of Columbia", 'FL'=>"Florida", 'GA'=>"Georgia", 'HI'=>"Hawaii", 'ID'=>"Idaho", 'IL'=>"Illinois", 'IN'=>"Indiana", 'IA'=>"Iowa", 'KS'=>"Kansas", 'KY'=>"Kentucky", 'LA'=>"Louisiana", 'ME'=>"Maine", 'MD'=>"Maryland", 'MA'=>"Massachusetts", 'MI'=>"Michigan", 'MN'=>"Minnesota", 'MS'=>"Mississippi", 'MO'=>"Missouri", 'MT'=>"Montana", 'NE'=>"Nebraska", 'NV'=>"Nevada", 'NH'=>"New Hampshire", 'NJ'=>"New Jersey", 'NM'=>"New Mexico", 'NY'=>"New York", 'NC'=>"North Carolina", 'ND'=>"North Dakota", 'OH'=>"Ohio", 'OK'=>"Oklahoma", 'OR'=>"Oregon", 'PA'=>"Pennsylvania", 'RI'=>"Rhode Island",'SC'=>"South Carolina",'SD'=>"South Dakota",'TN'=>"Tennessee",'TX'=>"Texas",'UT'=>"Utah",'VT'=>"Vermont",'VA'=>"Virginia",'WA'=>"Washington",'WV'=>"West Virginia",'WI'=>"Wisconsin",'WY'=>"Wyoming");
$states = array('AL'=>"Alabama",
'AK'=>"