Skip to content

Instantly share code, notes, and snippets.

View logichub's full-sized avatar

Kashif Rafique logichub

View GitHub Profile
@zanematthew
zanematthew / routes.php
Created June 19, 2012 02:48
Custom routes for using WordPress as an Application
<?php
/**
* This file handles redirecting of our templates to our given views
* dir and anything else.
*
* Check if the themer has made a theme file in their
* theme dir, if not load our default.
*
* @uses template_redirect http://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect
*/
@mikejolley
mikejolley / gist:2974310
Created June 22, 2012 18:13
WooCommerce - Set default state/country for checkout
/**
* Manipulate default state and countries
*
* As always, code goes in your theme functions.php file
*/
add_filter( 'default_checkout_country', 'change_default_checkout_country' );
add_filter( 'default_checkout_state', 'change_default_checkout_state' );
function change_default_checkout_country() {
return 'XX'; // country code
@zanematthew
zanematthew / gist:3099863
Created July 12, 2012 18:15
Sample auto loader
<?php
/**
* Start auto loading
*
* Everything is based on the presence of a plugin/your-plugin/controller/{$post_type}_controller.php
* file if this file is present it is read and $post_type is paresed out and used for the model, js,
* and css file. If a css or js file isn't present one will be created for you given we can write to
* the dir.
*/
@zanematthew
zanematthew / upload.php
Created July 23, 2012 16:00
Here's how I'm using zm-upload inside of a plugin and resizing images.
<?php
if ( ! empty( $_FILES ) ) {
$media = new MediaUpload;
$uploaded_media = $media->saveUpload( $field_name='Filedata' );
/**
* @todo MediaUpload does NOT handle resizing of images,
* normally its done in WordPress, but for some reason
@johnpolacek
johnpolacek / gist:3827270
Last active January 20, 2023 15:46
Prevent FOUC
<!-- Prevent FOUC (flash of unstyled content) - http://johnpolacek.com/2012/10/03/help-prevent-fouc/ -->
<style type="text/css">
.no-fouc {display: none;}
</style>
<script type="text/javascript">
document.documentElement.className = 'no-fouc';
// add to document ready: $('.no-fouc').removeClass('no-fouc');
</script>
@johnbillion
johnbillion / gist:5225514
Last active May 29, 2019 12:56
Post Meta Revisions
<?php
/*
Plugin Name: Post Meta Revisions
Description: Revisions for the 'foo' post meta field
Version: 1.0
Author: John Blackbourn
Plugin URI: http://lud.icro.us/post-meta-revisions-wordpress
*/
@jdevalk
jdevalk / archive-wpseo_locations.php
Last active July 14, 2019 23:32
A cool example of what your locations post type archive page could look like
<?php
/**
* Template for displaying a map on the locations post-type archive page.
*
* @package Twenty_Twelve
* @subpackage Local SEO for WordPress Archive page template
* @author Joost de Valk
*/
get_header();
@jdevalk
jdevalk / gist:5345863
Last active December 16, 2015 00:09
Fix XML sitemaps to work by forcing .htaccess to pick them up. Add this to the .htaccess, **above** the WordPress rewrites.
# WordPress SEO - XML Sitemap Rewrite Fix
RewriteEngine On
RewriteBase /
RewriteRule ^sitemap_index.xml$ /index.php?sitemap=1 [L]
RewriteRule ^([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 [L]
RewriteRule ^([a-z]+)?-?sitemap.xsl$ /index.php?xsl=$1 [L]
# END WordPress SEO - XML Sitemap Rewrite Fix
@jdevalk
jdevalk / gist:5345872
Created April 9, 2013 13:57
Fix XML sitemaps to work by forcing .htaccess to pick them up. Add this to the .htaccess, above the WordPress rewrites. This version assumes you're using a subfolder install with WordPress installed in /wordpress/, adapt if needed.
# WordPress SEO - XML Sitemap Rewrite Fix
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^sitemap_index.xml$ /wordpress/index.php?sitemap=1 [L]
RewriteRule ^([^/]+?)-sitemap([0-9]+)?.xml$ /wordpress/index.php?sitemap=$1&sitemap_n=$2 [L]
# END WordPress SEO - XML Sitemap Rewrite Fix
@jdevalk
jdevalk / gist:5411371
Created April 18, 2013 09:12
NGINX rewrites for WordPress SEO XML Sitemaps
# Rewrites for WordPress SEO XML Sitemap
rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;