Custom Post Types or Choose Your Own Adventure – WordCamp Atlanta 2014

I’ve been fortunate enough to be able to present at WordCamp Atlanta 2014. That makes the 3rd year in a row I’ve been able to contribute to WordCamp Atlanta!

WCATL-Speaker

Here are my slides. I’ll be posting a full blown post of my presentation as soon as I can get it all down. Plus I hear there will be a video posted to wordpress.tv at some point, so, watch for that.

WordPress presentations on WordPress.tv

I’ve made presentations at WordCamp Atlanta for the past two years. I’d been told the presentation was recorded and would be added to the repository of wordcamp presentations at wordpress.tv both times, long story short. They have both made it online now. Thanks to whoever posts them and Happy Birthday WP. Enjoy the presentations!

WordCamp Atlanta 2012
Evan Mullins: From PSD to WordPress Theme: Under the Skin
This presentation covers how to get from Photoshop to WordPress. There are many different roads to a theme. Covering a few possibilities and then cover getting from a design in Photoshop to an actual WordPress child theme while trying not to reinvent the wheel.
http://wordpress.tv/2013/05/24/evan-mullins-from-psd-to-wordpress-theme-under-the-skin/

 

WordCamp Atlanta 2013
Evan Mullins: Your Firstborn Child Theme- Child Themes 101+102
Learn how to mod themes the right way. Using child themes you won’t loose your edits when there’s a theme update.
http://wordpress.tv/2013/05/04/evan-mullins-your-firstborn-child-theme-child-themes-101102/

Leveling Up Your Authorship Skills with Google Plus

Otto has a great post over on make.wordpress explaining how to associate your WordPress plugins with yourself as the author in Google search results. I just tried it, easy, and it worked.

While Google+ may not be the hot social area on the block, it does seem to have some benefits. Studies show that listings with a specified author receive much more clicks and attention than those that do not.

Who doesn’t want more attention to their hand-crafted WordPress plugins? More traffic? More readers? More leads? More collaborators…?

google authorship screenshotI think it makes the listing much more attractive as well, of course, that all depends on your mug too =)

Plugin authors developers are “contributors” to WordPress and should be benefiting from these Google author listings.

Go set up your WordPress profile with a link to Google+ as well as a link to your WordPress profile on your Google+ profile.

This gives Google the data they need to give you “credit” for your work in their search listings. Not that this by any means guarantees that your listings will include this data, but it does do all the set up so it is possible.

Google also provides a Rich Snippet Tool to preview and test that all your associations are set up properly. So don’t stop at WordPress. To me, this is all related to branding, and in having a consistent showing and presence across the web.

Presenting at WordCamp Atlanta – Child Themes

The presentation? Your firstborn child theme. Child themes 101+2.

I’m speaking at wordcamp atlanta this afternoon about themes and child themes. I’ll update this post with post-presentation notes.

Learn how to mod themes the right way. Using child themes you won’t loose your edits when there’s a theme update. (101) We’ll go over the advantages and how to set up a child theme. (102) Plus we’ll cover some tricks to make the process a bit easier.

Slides on slideshare

Presentation video via wordpress.tv

Hooks, In a Nutshell – WP Daily

I’ve published another article over on wpdaily.co exploring the concept of hooks. I remember when starting out that people kept mentioning hooks and filters and actions and… it took a while to grasp what they each meant. I think the first time I started to grasp it was when I read the codex and saw this:

You can sometimes accomplish the same goal with either an action or a filter. For example, if you want your plugin to change the text of a post, you might add an action function to publish_post (so the post is modified as it is saved to the database), or a filter function to the_content (so the post is modified as it is displayed in the browser screen).

And realized that actions and filters are each kinds of hooks. In the post I use a metaphor of procedural programming as people standing in a line waiting to register at the DMV. I hope it will help you understand hooks a little bit better. read it now at Hooks, In a Glorious Nutshell – WP Daily.

Hooks, In a Glorious Nutshell

Are you familiar with hooks, actions and filters?

If not, then this might be your seriously-simple primer. Let me quickly give you some thoughts about hooks, actions and filters. You can probably take it from there.

Order of Operations

Websites and any programming (procedural at least) has an order that things are done in. They are done in this same order every time and many pains are made to ensure this.

Think of something simple that you engage with every single day, like starting a car. Insert keys, turn keys, hold for a brief moment, and then release. Car starts. There is no alternative way to do this with your current vehicle (unless you buy a new one with those fancy “auto start” features). This is a procedure, and order of how things are done.

If something is out of order in can confuse and confound the programming. Especially a website, and WordPress is no different. Things all happen in a certain order when a page is created on the sever via php and delivered to the client as html.

The server reads the php and goes through all the commands pulling data from the database and placing it in the proper place. This is great and keeps everything running smoothly and webpages loading nicely and properly.

DMV
Ah, the lovely DMV…

So, Hooks…

Imagine now that you wanted to alter or modify how something, somewhere happened (vague, I know) and needed to interrupt or have access to this execution order. This is where hooks come in.

Think of this execution order as a line or queue at the DMV or at a busy clinic. Everyone comes in and takes a number and sits down to wait their turn. Everyone has their own agenda in this case with their individual business not too dependent on each other, and things will move much much slower than your website, but focus on the ordering concept.

Imagine this is your program, everyone has their data and they bring it to the forefront at the needed time and deposit it or something is done with it. A single file line of ‘actions’ that need doing to accomplish the goal of the program/site/business.

This is similar to a program, website or in our case WordPress. Think about the time each number is called. There is a little space before the person with that number gets to the desk, then they do their business, and there is a time after they leave the desk before the next number is called.

These brief time periods are hooks. In programming sometimes they are set aside and a hook is built into the code, so you can do something before the person gets to the desk, or something with the data they bring after they have brought it.

Where Now?

Now that you’ve got the very basics of hooks and how this works, it’s time for you to learn to build your own, or at least experiment a little.

For starters:

  1. Plugin API
  2. Filter Reference
  3. Action Reference
  4. Tom McFarlin’s Primer
  5. Tom McFarlin’s WP Tut’s Guide
  6. Smashing Magazine’s Guide

Get goin’!

Speaker at WordCamp Atlanta 2013

speaker-lineupI’m excited to be speaking at WordCamp Atlanta again this year! The time is quickly approaching for WordCamp Atlanta 2013, March 15-16.

I spoke last year and discussed the process of going from Photoshop PSD to WordPress Theme, here are my slides and notes for that WordCamp Presentation.

This year I’m speaking along the same lines but more specifically about how to create a child theme. Here is the description:

Your firstborn child theme. Child themes 101+2
Learn how to mod themes the right way. Using child themes you won’t loose your edits when there’s a theme update. (101) We’ll go over the advantages and how to set up a child theme. (102) Plus we’ll cover some tricks to make the process a bit easier.

Fear not, I’ll share slides and notes on this presentation as I can. First, I’ve got to go prepare.

Do you have any pain points or specific questions you’d want addressed regarding creating child themes I could work in and answer for you? Hope to see you there!

Speaker Lineup | WordCamp Atlanta.

WP Features: Theme or Plugin

Reading my wpdaily.co updates today and saw this post talking about WordPress theme features. Eric explains the debate:

Generally-speaking, the conversations have always circled around features: There are those that believe every feature you could ever imagine should be included like text color, font selector, and more. On the flip-side, there are those that feel WordPress themes should be finite and extra features should only be added when it’s niche specific.

He says the the main problem is theme bloat, but I think it’s more about the lock-in effect some themes have on users. If they customize it or add content via functionality provided by the theme, then if they switch they no longer have access to it (although the content does persist in the database, there’s just no longer an interface to accessing it).

many-theme-options

If users are stuck in your theme because it’s the only way they know how to show their content then it becomes problematic. I’m curious as to how often users are going around changing themes though. Are they changing themes for more/different functionality or for a new look? I find myself changing a theme every couple years or so to update the site, but that’s usually in a whole redesign phase and not just switching around for fun. Should theme switching be more frequent?

I also see it from the user perspective. They just want to purchase/install a theme and be running, they may not have the patience or expertise to 1) find the right plugin 2) install it and set it up, so they’d prefer it be in the theme as a package deal.

Partly, I don’t see it a problem including CPT info in a theme, because that’s where you have to style it anyways, right? Users want their post types, but they also want the templates and styles and functionality/integration with the site that go along with them, and I think a theme is the easiest place to keep all that for the developers as well as the users. Plugin shouldn’t have all the styles for the CPT content and can’t have the template files because then if they switch the theme the styles conflict with the new theme. They may end up having to learn CSS to switch the theme anyways. The users are going to want their data displayed properly as well as it be accessible on their site. So if a new theme would not properly display or integrate the CPT data, then why have it included at all.

Eric does offer some alternative solutions:

Offer a Support License purchase option that allows users to follow tutorials for their own customization.
Offer free downloadable plugins that work exclusively with your premium theme that adds easy functionality.
Offer tiered theme versions–beginner, advanced and developer.

I like the idea of including a plugin to add functionality, but I’d suggest that rather than making it exclusive, make it work with any theme, just make sure your theme supports it (along with other popular plugins).

There is talk about making extra theme functionality ‘opt-out’ for those experienced enough to do so. Set a variable in the functions.php file or even comment out a block of code to remove some customization options to it can be done via a plugin. This, although more work, seems like a good option. Providing the features by plugin makes sense, but asking beginner users to do that extra work seems like unnecessary friction.

Also, it’d be nice if WP had a built in UI for custom post types and custom taxonomies and even custom fields and meta boxes in core. Lay users could then easily create content types and manage data. WordPress would be a tool to create your own custom CMS. Theme developers could create post types as well and then WP would be smart enough to detect data in a CPT table and include the needed UI. Then the users could create/manage content types so if they installed a theme that created a custom post type, since it was now in the database, it would stay even if the theme changed. There are many rabbit holes here, but I feel like I’m onto something and would be excited to see WordPress go this direction.

Thoughts?

Add Parent Page Slug and Parent Template to WordPress Body Class

Add CSS body classes for the parent page on all child pages and the parent page template on of a WordPress site with this body_class filter. Ever need to style all child pages of a parent page in the same way or have you wanted to access every child page of a parent page via css selectors for styling? What about selecting all pages that are descendants of a page which is using a specific template?

body_classes_htmlBuilding large websites gets complicated, even in WordPress. Large sites usually mean there are many subpages and sections to the website that may need to be styled similarly. I’ve found it helpful to add a page’s parent page slug to the body class to allow me to alter or target the page or group of pages via css. By default the themes I’ve used have been generous in adding classes to the html body element for easy css selection rules. Things like the post slug, page template, logged in status, page vs post (or custom post type), post id, author… you get the idea. While half the time I don’t need half of this and the other half the time I find myself needing more.

Place this code into your functions.php file and your html body element will have a couple additional classes if they apply. It will have a class delineating the slug for the parent page on all child pages as well as a class delineating the template used by the parent page. This lets me apply styles to a whole sibling-section of a site pretty easily by just targeting the parent-slug on the body. Also adding the template of the parent in case I needed to use that.

post_parent_classesWalking through the code here we’re filtering the body_class function is how we are able to add this. We name our own function and give it a $classes parameter. Then throughout our function we can add classes to this $classes array and they will be output with the rest of the body classes. We need to hook into WordPress at the body_class function with add_filter and specify the hook and specify our own function to be called. In this case we grab the page properties of post_parent and the template of that parent. First set the post variable to reference the global scope, and then check to see if the post is a page with is_page. Then if the post object has a value for the parent (post_parent) we add the parent’s name to the classes array. Then we get the _wp_page_template meta data from the parent to find the template it’s using (if there is no template specified, then it returns default). This is added to our classes if it exists and then we return the classes array to the original body_class WP core function.

[cc lang=”php”]
/////////////////////////////////////////////////////////////////////////////////
// Body class adding page-parent
//
function cc_body_class( $classes ) {
global $post;
if ( is_page() ) {
// Has parent / is sub-page
if ( $post->post_parent ) {
# Parent post name/slug
$parent = get_post( $post->post_parent );
$classes[] = ‘parent-slug-‘.$parent->post_name;
// Parent template name
$parent_template = get_post_meta( $parent->ID, ‘_wp_page_template’, true);
if ( !empty($parent_template) )
$classes[] = ‘parent-template-‘.sanitize_html_class( str_replace( ‘.’, ‘-‘, $parent_template ), ” );
}
}
return $classes;
}
add_filter( ‘body_class’, ‘cc_body_class’ );
[/cc]

There are many more classes we can add to the body_class and like I said, sometimes you need more than what’s already provided and sometimes you need nothing. It all depends on the theme you’re using, what it provides and what your specific site and design require. What other classes have you wanted to see here? How have you filtered body_class to fit your site’s needs?

Set Default Terms for your Custom Taxonomies

Custom Taxonomy Default Term(s) for when it’s left blank

After looking through the WP codex and various plugins, I couldn’t find anywhere to set a custom taxonomy default term. WordPress has allowed us to create custom taxonomies for a while. Before we only had categories and tags hard coded in core. One feature from those days that didn’t seem to make it to the custom taxonomies of today is the possibility to select a default taxonomy term if none are selected. Did you know about this feature? Odds are you did, even if you didn’t realize it. Have you ever seen that ‘uncategorized’ category? That was the default category added for any content that didn’t have a specific category and was left, well, uncategorized.
uncategorized-default-post-category
An annoying feature if you weren’t expecting it, but nice to have if you took the moment to actually set up your default properly. I was working on a project recently with custom post types and custom taxonomies and suddenly needed this feature, but it didn’t seem to exist, so a few google’s later I found this nice snippet from Micheal Fields. Adopting the hook and adding some to allow for custom post types I wanted to share it here for my own safe keeping as well as the benefit of the community.

To Code Custom Taxonomy Default Terms

[cc lang=”php”]
/**
* Define default terms for custom taxonomies in WordPress 3.0.1
*
* @author Michael Fields http://wordpress.mfields.org/
* @props John P. Bloch http://www.johnpbloch.com/
* @props Evan Mulins https://circlecube.com/circlecube/
*
* @since 2010-09-13
* @alter 2013-01-31
*
* @license GPLv2
*/
function mfields_set_default_object_terms( $post_id, $post ) {
if ( ‘publish’ === $post->post_status && $post->post_type === ‘your_custom_post_type’ ) {
$defaults = array(
‘your_taxonomy_id’ => array( ‘your_term_slug’ )
//’your_taxonomy_id’ => array( ‘your_term_slug’, ‘your_term_slug’ )
);
$taxonomies = get_object_taxonomies( $post->post_type );
foreach ( (array) $taxonomies as $taxonomy ) {
$terms = wp_get_post_terms( $post_id, $taxonomy );
if ( empty( $terms ) && array_key_exists( $taxonomy, $defaults ) ) {
wp_set_object_terms( $post_id, $defaults[$taxonomy], $taxonomy );
}
}
}
}
add_action( ‘save_post’, ‘mfields_set_default_object_terms’, 100, 2 );
[/cc]
This code hooks to ‘save_post’ and fires when the post is saved. It will check the post status and only execute if the post status is set to publish. My addition will also check the post type against your custom post type. Then it sets the default for any taxonomy that you want to set a default for. Either a single term or multiple terms can be set as the default taxonomy term. If you want multiple default terms then you just use a comma separated list. This hook will then load the existing taxonomies and if they are not yet set on the post it will set them to your designated default(s). It’s nice and flexible as you can have multiple taxonomy defaults set quickly in the defaults array. Thanks Michael!

Set Default Terms for your Custom Taxonomies via Michael Fields » Set Default Terms for your Custom Taxonomies.