Skip to content

Instantly share code, notes, and snippets.

View Jonnyauk's full-sized avatar
🎯
Focusing

Jonny Allbut Jonnyauk

🎯
Focusing
View GitHub Profile
@Jonnyauk
Jonnyauk / wp-jonnya-cpt-right-now.php
Created May 12, 2012 15:56
WordPress custom post type 'Right Now' panel integration
<?php
// Add all your custom post type counts to 'Right Now' dashboard widget
function tanc_admin_post_types_rightnow(){
$post_types = get_post_types(array('_builtin' => false), 'objects');
if (count($post_types) > 0)
foreach ($post_types as $pt => $args) {
$url = 'edit.php?post_type=' . $pt;
echo '<tr><td class="b"><a href="' . $url . '">' . wp_count_posts($pt)->publish . '</a></td><td class="t"><a href="' . $url . '">' . $args->labels->name . '</a></td></tr>';
}
@Jonnyauk
Jonnyauk / wp-post-publish-first.php
Created June 25, 2012 14:35
Detect if WordPress post is published for the first time
<?php
/*
* On first publish set a special date in advance in custom field
*/
add_action('transition_post_status','tanc_first_schedule_publish_set',10,3);
function tanc_first_schedule_publish_set($new, $old, $post) {
// REFERENCE
// $new = new post status ('publish')
// $old = old post status ('draft')
@Jonnyauk
Jonnyauk / unbrand-wonderflux.php
Last active December 20, 2015 07:09
Wonderflux has lots of filters for you to manipulate the output. Here's how to change the footer and comment credit - NOTE: You are free to do this, there is no requirement to give Wonderflux credit (although it would be appreciated - at-least tell your WordPress buddies!)
<?php
// Just a simple text string that appears near the footer as a HTML comment (view source)
function my_wfx_filter_code_credit() {
return 'Designed and coded by Wonderflux. Powered by WordPress and the Wonderflux theme framework.';
}
add_filter( 'wflux_comment_code_credit', 'my_wfx_filter_code_credit' );
// Replace the footer credit with your own text
function my_wfx_filter_footer_credit() {
return '<p class="meta">All content &copy;' . date('Y') . ' My Company | Website design &amp; coding by <a href="http://www.wondeflux.com" class="footer-credit-logo" title="Website design and coding by Wonderflux">Wonderflux</a></p>';
@Jonnyauk
Jonnyauk / gist:16aefac2db04485b2da9
Created February 7, 2015 00:00
pre_get_posts example
<?php
function mywfx_archive_order_by_title($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ( is_post_type_archive( ‘kitty’ ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
return $query;
}
}
@Jonnyauk
Jonnyauk / gist:0720b69d73acf55418b6
Created February 7, 2015 00:01
Debug function from Wonderflux
<?php
/**
* Displays input in a nicer way for debugging
* Only displays for top level site admin by default
* Part of the Wonderflux theme framework
*
* @param string $input The content you wish to debug - a variable or function.
* @param string $admin_only Only display to top level site admin not other users. Default=true
* @param bool $role Only display to supplied WordPress role. Default = ''
* @param integer $id Only display to supplied user ID. Default = ''
@Jonnyauk
Jonnyauk / gist:4cde7d870791a4493b1a
Created February 7, 2015 00:10
Using WordPress _n
<?php
$my_value = 5;
printf( _n( 'Counting just 1 time', 'Counting %s times, whoot!', $my_value, 'mytheme' ), $my_value );
?>
@Jonnyauk
Jonnyauk / gist:94c2cc4fbdcffc378651
Created February 7, 2015 00:24
Empty menu callback
<?php
/*
NOTE: Insert into template file as usual but use fallback_cb parameter - same name as function
wp_nav_menu( array(
'container_class' => 'primary-navigation clearfix',
'theme_location' => 'primary-nav',
'fallback_cb' => 'mywfx_empty_menu'
) );
*/
@Jonnyauk
Jonnyauk / remove_core_emoji.php
Last active August 29, 2015 14:20
Remove crazy WordPress 4.2 Emoji support
<?php
/**
* Remove crazy WordPress 4.2 Emoji junk
*/
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
?>
<?php
/**
* BRIEF DESCRIPTION OF FUNCTIONALITY
*
* @package PACKAGE NAME
*/
/*
@Jonnyauk
Jonnyauk / typography-test.htm
Created April 29, 2016 09:34
Useful when building a typography size stack
<h1>h1 title style</h1>
<h2>h2 title style</h2>
<h3>h3 title style</h3>
<h4>h4 title style</h4>
<h5>h5 title style</h5>
<h6>h6 title style</h6>
<h1>h1 title here, lets just check multi-line support and leading/spacing thanks to make sure we are good!h1 title here, lets just check multi-line support and leading/spacing thanks to make sure we are good!</h1>
Donec sed odio dui. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Vivamus sagittis lacu eu leo. Donec id elit non mi porta gravida at eget metus. Sed posuere consectetur est at lobortis.
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Cras mattis consectetur purus sit amet fermentum. Nullam id dolor id nibh ultricies vehicula.