Skip to content

Instantly share code, notes, and snippets.

View danemorgan's full-sized avatar

Dane Morgan danemorgan

View GitHub Profile
@danemorgan
danemorgan / wp-count-users-by-role.php
Created September 14, 2013 05:30
Get the number of users currently assigned to specified role.
function count_users_by_role( $user_role ) {
// Standard User Roles: all, administrator, editor, author, contributor, subscriber
$result = count_users();
$totalUsers = $result['total_users'];
if( 'all' == $user_roll || '' == $user_roll ) :
return $totalUsers;
else :
@danemorgan
danemorgan / wp-bypass-front-page-home-posts.php
Created September 14, 2013 06:43
Bypass the `front-page.php` template if posts are set to show on the front in settings.
add_filter( 'front_page_template', 'my_front_page_template' );
function my_front_page_template( $template ) {
return is_home() ? '' : $template;
}
@danemorgan
danemorgan / genesiswp-set-content-width-by-layout.php
Last active December 23, 2015 10:59
Set $content_width of various #genesiswp layouts for use with #jetpack #tiled_galleries ( http://jetpack.me/support/tiled-galleries/ ).
<?php
$site_layout = genesis_site_layout();
if ( 'content' == $site_layout ) {
$content_width = 1060;
}else if ( 'content-sidebar' == $site_layout || 'sidebar-content' == $site_layout )
$content_width = 760;
}else if ( 'content-sidebar-sidebar' == $site_layout || 'sidebar-sidebar-content' == $site_layout )
$content_width = 560;
}else if ( 'content-sidebar-sidebar' == $site_layout || 'sidebar-sidebar-content' == $site_layout )
$content_width = 460;
@danemorgan
danemorgan / wp-post-word-count.php
Created September 28, 2013 12:16
Count the number of words in a WordPress post
<?php //count number of words in a post
function post_word_count($id) {
global $post
if ( !$id ) $id = $post->ID;
$content = get_post_field( 'post_content', $id );
$count = str_word_count( strip_tags( $content ) );
return $count;
}
@danemorgan
danemorgan / genesiswp-add-main-id.php
Last active September 20, 2016 11:35
Adds an ID attribute to the .main element in Genesis 2.0 HTML5. Useful for hooking into things like ajax post loaders and infinite scrollers. #genesiswp #wpfilter
<?php
add_filter( 'genesis_attr_content', 'themename_attributes_content' );
function themename_attributes_content( $attributes ) {
$attributes['id'] = 'primary-content';
return $attributes;
}
@danemorgan
danemorgan / check_for_last_week.php
Last active August 29, 2015 13:56
is_last_week() function for determining if the current date is in the last seven days of the current month.
<?php
include ('is_last_week.php');
if ( is_last_week() ) :
echo 'We are in the last week of the month';
else :
echo 'We havent reached the last week yet this month.';
endif;
For more details, see http://code.garyjones.co.uk/install-wordpress-ssh/
wget http://wordpress.org/latest.tar.gz
tar zxf latest.tar.gz
cd wordpress
cp -rpf * ../
cd ../
rm -rf wordpress/
rm -f latest.tar.gz
<?php
################################################################################
// Custom WordPress Local Config
// Use only for Development
// https://gist.github.com/bhubbard/8428583
################################################################################
/* Database Connection Info */
define('DB_NAME', '');
define('DB_USER', '');
@danemorgan
danemorgan / wget.sh
Last active August 29, 2015 14:06 — forked from lyoshenka/wget.sh
wget --mirror --page-requisites --continue --convert-links --user-agent="" --execute robots=off --wait 1 URL
@danemorgan
danemorgan / widget-shortcodes.php
Created September 24, 2014 17:28
Add shortcode capabilities to WordPress widgets
// Enable shortcodes in widgets
add_filter('widget_text', 'do_shortcode');