Skip to content

Instantly share code, notes, and snippets.

@dannyockilson
dannyockilson / lipsum shortcode
Created May 17, 2013 14:33
Wordpress Function to add [lipsum] | [lipsum amount="int"] | [lipsum type="{ paras | words | bytes | lists }"]
function lipsum_shortcode($atts) {
extract(shortcode_atts(array('amount' => 1, 'type' => 'paras'), $atts));
$lipsum = simplexml_load_file("http://www.lipsum.com/feed/xml?amount=$amount&what=$type")->lipsum;
return $lipsum;
}
add_shortcode('lipsum', 'lipsum_shortcode');
@dannyockilson
dannyockilson / of_section_hider
Last active December 17, 2015 11:59
Hide sections of options when using Wordpress Options Framework http://wptheming.com/options-framework-theme/
// In options.php
$options[] = array(
'name' => __('Example Hide', 'options_framework_theme'),
'desc' => __('Example Hide Multiple Fields', 'options_framework_theme'),
'id' => 'example_showhidden',
'type' => 'checkbox');
$options[] = array(
'name' => __('Example Hidden 1', 'options_framework_theme'),
@dannyockilson
dannyockilson / gist:6509594
Created September 10, 2013 13:44
Simple Wordpress Secured Content Shortcode: Add this to your functions.php to enable [is_logged_in]Members only content[/is_logged_in] and [not_logged_in]Non Members content[/not_logged_in] in posts/pages
function is_logged_in($atts, $content){
if(is_user_logged_in()){
return do_shortcode($content);
}
else {
// this is used incase you want to attach an icon/message to show more information is available on login
return "<span class='secured'></span>";
}
}

Animated Navigation Style

Alternative Navigation Style using CSS3 animations and transitions.

A Pen by Danny on CodePen.

License.

@dannyockilson
dannyockilson / gist:8438642
Created January 15, 2014 15:50
Drop-in for custom wp-mail settings
/* Set Default Mail From Name */
function custom_wp_mail_from_name( $original_email_from ){
return 'Danny Wilson';
}
add_filter( 'wp_mail_from_name', 'custom_wp_mail_from_name' );
/* Set Default Mail From email */
function custom_wp_mail_from( $original_email_address ){
return 'danny@iamdannywilson.com';
}
@dannyockilson
dannyockilson / custom_options.php
Created May 15, 2014 18:43
Set custom Wordpress Options Table
<?php
// Add this into wp-db.php at line 954
if ( isset( $tables['options'] ) && defined( 'CUSTOM_OPTIONS_TABLE' ) )
$tables['options'] = CUSTOM_OPTIONS_TABLE;
?>
<?php
// Add this to your wp config file
define('CUSTOM_OPTIONS_TABLE', 'api_options');
?>
@dannyockilson
dannyockilson / wordpress.sql
Created May 27, 2014 17:18
SQL Queries for Wordpress
/* Switch off comments and remove for already created posts */
UPDATE {{database}}.{{prefix}}posts SET comment_status = 'closed' WHERE comment_status = 'open';
UPDATE {{database}}.{{prefix}}options SET option_value = 'closed' WHERE option_name = 'default_comment_status';
/* Lost password on localhost/no mail server */
UPDATE {{database}}.{{prefix}}users
SET password = MD5('{{password}}')
WHERE user_id = 1; /* normally replace with relevant user ID */
/* Somethings broke - deactivate all plugins and use default theme */
@dannyockilson
dannyockilson / gist:79865d873bf8575bd52c
Created June 5, 2014 10:52
Add "Ordinal Suffix" to a number (ie 1->1st)
function iadw_get_ordinal_suffix($number){
$ends = array('th','st','nd','rd','th','th','th','th','th','th');
if (($number %100) >= 11 && ($number%100) <= 13)
$abbreviation = $number. 'th';
else
$abbreviation = $number. $ends[$number % 10];
return $abbreviation;
}
@dannyockilson
dannyockilson / privacy.php
Last active August 29, 2015 14:02
Wordpress Private site
function iadw_login_redirection(){
auth_redirect();
}
add_action( 'wp_head', 'iadw_login_redirection' );
/* to allow visitors to access your home page only just switch the function to
* if(!is_home()) auth_redirect();
*/
@dannyockilson
dannyockilson / media-categories
Created July 3, 2014 10:40
Enable Media Categories Wordpress
<?php
/* add this on init hook */
register_taxonomy_for_object_type( 'category', 'attachment' );
?>