Skip to content

Instantly share code, notes, and snippets.

View danemorgan's full-sized avatar

Dane Morgan danemorgan

View GitHub Profile
@danemorgan
danemorgan / debug-on-demand.wp-config.php
Last active December 22, 2015 02:49
On demand WordPress debugging display with always on logging. Put this code in your wp-config.php then wen you load a page and something goes wrong reload it with /?debug This is intended for develpment sites.
<?php
// Turn on logging for dev environment
define('WP_DEBUG', true); // or false
define('WP_DEBUG_LOG', true);
@ini_set('display_errors',0);
// Add debugging display on demand through a get variable
if ( isset($_GET['debug']) && $_GET['debug'] == 'debug') :
define('WP_DEBUG_DISPLAY', true);
else :
add_filter('nav_menu_link_attributes' , 'att_add_menu_id', 3, 10);
if ( !function_exists( 'att_add_menu_id') ) {
function att_add_menu_id($atts, $item, $args) {
if( 'page' == $item->object ){
$id = $item->object_id;
$id = 'page-'. esc_attr( basename( get_permalink( $id ) ) );
$atts['id'] = $id;
}
return $atts;
}
@danemorgan
danemorgan / IE conditional tags for scripts in wp_head
Last active December 22, 2015 08:29 — forked from GaryJones/functions.php
.Untested. Should wrap javascript in ie conditional tags. Will update after testing.
<?php
add_action( 'wp_enqueue_scripts', 'child_add_ie_script', 200 );
/**
* Enqueue a IE-specific style sheet (for all browsers).
* @author Gary Jones
* @link http://code.garyjones.co.uk/ie-conditional-style-sheets-wordpress/
*/
function child_add_ie_script() {
@danemorgan
danemorgan / IE conditional tags for stylesheets in wp_head
Last active December 22, 2015 08:38 — forked from GaryJones/functions.php
Wrap stylesheet in ie conditional tags for wp_head
<?php
add_action( 'wp_enqueue_scripts', 'child_add_ie7_style_sheet', 200 );
/**
* Enqueue a IE-specific style sheet (for all browsers).
*
* @author Gary Jones
* @link http://code.garyjones.co.uk/ie-conditional-style-sheets-wordpress/
*/
function child_add_ie7_style_sheet() {
@danemorgan
danemorgan / front-page.php
Created September 10, 2013 10:23
Show posts on front page with front-page.php if the user has specifically selected show posts in the dashboard settings.
if ( 'posts' == get_option( 'show_on_front' ) ) { // if user has selected posts to show on the front page
include( get_home_template() ); // use a post enabled home page template
} else {
// Custom static front-page markup goes here
}
@danemorgan
danemorgan / wp-post-wordcount.php
Last active December 23, 2015 01:09
Get the word count for your Wordpress Posts
function post_wordcount($postid) {
$content = get_post($postid);
$completContent = $content->post_content;
$wordsCount = count(explode(" ", $completContent));
return $wordsCount;
}
function simplePostsCounter($type, $status) {
if($type == '') {$type = 'post';}
if($status == '') {$status = 'publish';}
$foundResults = wp_count_posts($type);
return $foundResults->$status;
}
@danemorgan
danemorgan / wp-posts-in-term.php
Last active December 23, 2015 01:18
Count the number of posts currently published in a specific category, tag or custom taxonomy.
function posts_in_term($catid, $taxonomy) {
$term_query = get_term($catid, $taxonomy);
return $term_query->count;
}
@danemorgan
danemorgan / wp-count-posts-by-user.php
Created September 14, 2013 05:20
Get the number of posts attributed to a specific author.
function count_posts_by_user($userID) {
$userposts = get_posts('showposts=-1&author='.$userID);
return count($userposts);
}
@danemorgan
danemorgan / wp-count-comments-by-user.php
Created September 14, 2013 05:23
Get the number of comments posted by user with specified email address.
function count_user_comments($user_email) {
$args = array(
'author_email' => $user_email
);
$user_comments_count = get_comments( $args );
return count($user_comments_count);
}