Skip to content

Instantly share code, notes, and snippets.

@adapicom
adapicom / gist:7378250
Created November 8, 2013 21:49
Display total count of published pages, posts or custom post types
<?php echo wp_count_posts('post')->publish; ?>
@adapicom
adapicom / gist:7268759
Created November 1, 2013 17:23
Wordpress: get custom field from a specific post/page ID
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta('4', 'qofday', true);
wp_reset_query();
add_action( 'wp_footer', 'tcb_note_server_side_page_speed' );
function tcb_note_server_side_page_speed() {
date_default_timezone_set( get_option( 'timezone_string' ) );
$content = '[ ' . date( 'Y-m-d H:i:s T' ) . ' ] ';
$content .= 'Page created in ';
$content .= timer_stop( $display = 0, $precision = 2 );
$content .= ' seconds from ';
$content .= get_num_queries();
$content .= ' queries';
if( ! current_user_can( 'administrator' ) ) $content = "<!-- $content -->";
@adapicom
adapicom / gist:7172794
Created October 26, 2013 18:17
Turn off automatic background updates in Wordpress (starting in version 3.7)
define( 'AUTOMATIC_UPDATER_DISABLED', true );
@adapicom
adapicom / gist:6299358
Created August 21, 2013 19:54
Allow HTML in Wordpress category descriptions.
remove_filter('pre_term_description', 'wp_filter_kses');
@adapicom
adapicom / gist:5878191
Last active December 19, 2015 01:48
Ad Inside Wordpress Content
<?php
$paragraphAfter= 7; //display after the first paragraph
$content = apply_filters('the_content', get_the_content());
$content = explode("</p>", $content);
for ($i = 0; $i <count($content); $i++ ) {
if ($i == $paragraphAfter) { ?>
<!-- Place Ad Content Here -->
<?php }
echo $content[$i] . "</p>";
} ?>
@adapicom
adapicom / gist:5785831
Created June 14, 2013 22:38
Simple A/B Test with PHP
<?php if (rand(1, 100) > 50) { ?>
<?php } else { ?>
<?php } ?>
@adapicom
adapicom / gist:5736765
Created June 8, 2013 22:05
Optimize Drupal Database
delete from cache_filter;
delete from cache_menu;
@adapicom
adapicom / gist:5736531
Created June 8, 2013 20:48
Get an RSS Feed inside Wordpress Theme
<ul>
<?php if(function_exists('fetch_feed')) {
include_once(ABSPATH . WPINC . '/feed.php');
$rssfeed = get_post_meta($post->ID, 'rssfeed', true);
$feed = fetch_feed($rssfeed);
$limit = $feed->get_item_quantity(10);
$items = $feed->get_items(0, $limit);
}
if ($limit == 0) echo '<div>The feed is either empty or unavailable.</div>';
@adapicom
adapicom / gist:5681247
Created May 30, 2013 21:07
Disable "wrong username" and "wrong password" text on wp-login.php
add_filter('login_errors',create_function('$a', "return null;"));