10
http://jonnya.net @jonnyauk http://wider.co.uk Theme building tricks of the trade Jonny Allbut - Creative Director

WordCamp Birmingham 2015 - Theme building tricks of the trade

Embed Size (px)

Citation preview

Page 1: WordCamp Birmingham 2015 - Theme building tricks of the trade

http://jonnya.net@jonnyauk http://wider.co.uk

Theme building tricks of the trade

Jonny Allbut - Creative Director

Page 2: WordCamp Birmingham 2015 - Theme building tricks of the trade

http://jonnya.net@jonnyauk http://wider.co.uk

‣Working with WordPress since 2005.

‣ Involved in WPUK group & co-organiser of Birmingham WordPress user group & WordCamp Birmingham.

‣ Likes to share:

‣ Wonderflux - free GPL theme framework http://wonderflux.com

‣ WP-CMS Post Control - control post editing capabilities http://wordpress.org/plugins/wp-cms-post-control

Howdy!

Page 3: WordCamp Birmingham 2015 - Theme building tricks of the trade

http://jonnya.net@jonnyauk http://wider.co.uk

‣wp-config.php

define( 'WP_DEBUG', false );

Day 1 - debug on!

Page 4: WordCamp Birmingham 2015 - Theme building tricks of the trade

http://jonnya.net@jonnyauk http://wider.co.uk

‣wp-config.php

define( 'SCRIPT_DEBUG', true );

No minified core CSS/scripts

Page 5: WordCamp Birmingham 2015 - Theme building tricks of the trade

http://jonnya.net@jonnyauk http://wider.co.uk

‣wp-config.php

define( 'DISALLOW_FILE_EDIT', true );

No editing files in admin

Page 6: WordCamp Birmingham 2015 - Theme building tricks of the trade

http://jonnya.net@jonnyauk http://wider.co.uk

‣Make your debugging easier to read

‣ Interrogate what data you are working with

‣http://wider.io/brum-debug

Turbo debug function

Page 7: WordCamp Birmingham 2015 - Theme building tricks of the trade

http://jonnya.net@jonnyauk http://wider.co.uk

$my_value = 1;

printf( _n( 'Counting just 1 time', 'Counting %s times, whoot!', $my_value, 'mytheme' ), $my_value );

‣http://wider.io/brum-num

Formatting string of text

Page 8: WordCamp Birmingham 2015 - Theme building tricks of the trade

http://jonnya.net@jonnyauk http://wider.co.uk

function mywfx_archive_posts_pp($query) {

if ( !is_admin() && $query->is_main_query() ) {

$query->set( 'posts_per_page', 5 );

return $query;

}

}

add_action( 'pre_get_posts', 'mywfx_archive_posts_pp', 1 );

Interacting with main query

Page 9: WordCamp Birmingham 2015 - Theme building tricks of the trade

http://jonnya.net@jonnyauk http://wider.co.uk

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;

}

}

add_action( 'pre_get_posts', 'mywfx_archive_order_by_title', 1 );

‣http://wider.io/brum-posts

Interacting with main query

Page 10: WordCamp Birmingham 2015 - Theme building tricks of the trade

http://jonnya.net@jonnyauk http://wider.co.uk

function mywfx_empty_menu() {

$page_data = wp_list_pages(array(

'post_type' => 'page',

'post_status' => 'publish',

'echo' => 0,

'number' => 3,

'title_li' => ''

));

echo '<ul class="menu">';

echo $page_data;

echo ( current_user_can( 'manage_options' ) ) ? '<li>' . '<a href="' . admin_url( 'nav-menus.php' ) . '">' . 'Edit this menu' . '</a>' . '</li>' : '';

echo '</ul>';

}

‣http://wider.io/brum-menu

Empty menus be gone!