Skip to content

Instantly share code, notes, and snippets.

View corsonr's full-sized avatar

Remi Corson corsonr

View GitHub Profile
@corsonr
corsonr / shortcode_in_text_widget
Created May 26, 2012 20:03
Allow shortcode in text widget
<?php
// To be able to use shortcode in text widget, add this line into functions.php
add_filter('widget_text', 'do_shortcode');
?>
@corsonr
corsonr / Easy Download Media Counter
Created May 29, 2012 10:42
Add counter to WP media
<?php
/*
Plugin Name: Easy Download Media Counter
Plugin URL: http://remicorson.com
Description: This plugin allows you to easily count downloads for a wordpress media and display it
Version: 1.0
Author: Rémi Corson
Author URI: http://remicorson.com
*/
@corsonr
corsonr / Translation in WordPress
Created May 31, 2012 13:03
How to translate properly
// String with a variable
printf(__("This string contains %d words."), $count);
// string with many variables
printf(__('Your city is %1$s, and your zip code is %2$s.'), $city, $zipcode);
// plural / singular
printf(_n("We deleted %d spam message.", "We deleted %d spam messages.", $count), $count);
@corsonr
corsonr / GitHub Gist WP Shortcodes Plugin
Created June 2, 2012 09:03
How to use GitHub Gist within Wordpress Shortcodes
<?php
/*
Plugin Name: Easy GitHub Gist Shortcodes
Plugin URI: http://www.remicorson.com/easy-github-gist-shortcodes
Description: Insert easily GitHub Gist within shortcodes this way [gist id="xxxxxx"]
Version: 1.0
Author: Remi Corson
Author URI: http://www.remicorson.com/
*/
@corsonr
corsonr / Shortcode outside the loop
Created June 8, 2012 07:49
Display a shortcode outside the loop
// Just place this line where you want the shortcode to be
echo do_shortcode('[shortcode option1="value1" option2="value2"]');
@corsonr
corsonr / Wordpress selected()
Created June 15, 2012 07:37
Nice selected() fucntion
<!-- Testing the values with if() -->
<select name="options[foo]">
<option value="1" <?php if ( $options['foo'] == 1 ) echo 'selected="selected"'; ?>>1</option>
<option value="2" <?php if ( $options['foo'] == 2 ) echo 'selected="selected"'; ?>>2</option>
<option value="3" <?php if ( $options['foo'] == 3 ) echo 'selected="selected"'; ?>>3</option>
</select>
<!-- Using selected() instead -->
<select name="options[foo]">
<option value="1" <?php selected( $options['foo'], 1 ); ?>>1</option>
@corsonr
corsonr / cpt icon
Created July 18, 2012 14:49
Add a cpt icon the right way
<?php
/* ------------------------------------------------------------------*/
/* CUSTOM CPTs ICONS */
/* ------------------------------------------------------------------*/
// let's say you custom post type is : portfolio
add_action( 'admin_head', 'cpt_icons' );
function cpt_icons() {
@corsonr
corsonr / db-error.php code
Created July 24, 2012 09:11
create a custom database error page
<?php
// Tell Search Engine
$protocol = $_SERVER["SERVER_PROTOCOL"];
if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol ) $protocol = 'HTTP/1.0';
header( "$protocol 503 Service Unavailable", true, 503 );
header( 'Content-Type: text/html; charset=utf-8' );
header( 'Retry-After: 600' );
// Get Variables
$temp = mysql_error();
@corsonr
corsonr / Custom CRON interval
Created July 25, 2012 09:11
Create a custom cron interval
/* ----------------------------------------
* ADD CRON CUSTOM INTERVALS
----------------------------------------- */
add_filter('cron_schedules', 'xxx_cron_every_two_days');
// add a cron interval every 2 days
function xxx_cron_every_two_days( $schedules ) {
$schedules['every_two_days'] = array(
'interval' => 172800, // in seconds
@corsonr
corsonr / Device-Pixel-Ratio Media Query
Created August 6, 2012 08:47
Using media queries for retina
@media (min--moz-device-pixel-ratio: 1.5),
(-o-min-device-pixel-ratio: 3/2),
(-webkit-min-device-pixel-ratio: 1.5);
(min-resolution: 1.5dppx) {
/* your retina rules here */
}