Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WordPress WTF

Adam Onishi
February 24, 2014

WordPress WTF

After you’ve spent many years working with something, you start to get to that point where you feel competent, that you can do anything and every problem has a solution. However, with this understanding you also get to a point where as well as seeing how something works, you can also see how badly it does it. This is the point Adam has come to with WordPress.

In this talk, you’ll take a look over some weaknesses with WordPress, exploring downsides of the architecture, the theming and some more general problems around the platform. But also you’ll see how to avoid these problems and write better themes, plugins, and websites with WordPress.

Video here: http://www.supermondays.org/2014/02/25/content-management-systems-videos/

Adam Onishi

February 24, 2014
Tweet

More Decks by Adam Onishi

Other Decks in Programming

Transcript

  1. @onishiweb Templates are built procedurally <?php get_header(); ?> <!-- Stuff

    --> <?php get_sidebar(); ?> <?php get_footer(); ?>
  2. @onishiweb Content Tags are alright <!-- Output the title -->

    <h1><?php the_title(); ?></h1> <!-- Return the title --> <h1><?php echo get_the_title(); ?></h1>
  3. @onishiweb If sometimes a little confusing <!-- Output the content

    formatted --> <?php the_content(); ?> <!-- Return the content, NO formatting --> <?php echo get_the_content(); ?>
  4. @onishiweb A bit more confusing... <?php // The Loop if(

    have_posts() ): while( have_posts() ): the_post(); /* Do stuff */ endwhile; endif; ?>
  5. @onishiweb IDs EVERYWHERE! <!-- Output of <?php body_class(); ?> -->

    <body class="home page page-id-7 page- template-default page"> <!-- Nav menu output --> <li id="menu-item-36" class="menu-item-pink menu-item menu-item-type-custom menu-item- object-custom menu-item-36">
  6. @onishiweb IDs EVERYWHERE! <!-- Output of <?php body_class(); ?> -->

    <body class="home page page-id-7 page- template-default page"> <!-- Nav menu output --> <li id="menu-item-36" class="menu-item-pink menu-item menu-item-type-custom menu-item- object-custom menu-item-36">
  7. @onishiweb IDs EVERYWHERE! <!-- Output of <?php body_class(); ?> -->

    <body class="home page page-id-7 page- template-default page"> <!-- Nav menu output --> <li id="menu-item-36" class="menu-item-pink menu-item menu-item-type-custom menu-item- object-custom menu-item-36">
  8. @onishiweb Add better classes function dig_add_useful_classes($classes) { global $post; if(

    ! is_tag() ) { $classes[] = dig_get_post_type_class(); } if( is_page() ) { global $post; $classes[] = 'page-' . $post->post_name; } return $classes; } https://gist.github.com/onishiweb/9151982
  9. @onishiweb Add better classes function dig_get_post_type_class( $type = false )

    { if( ! $type ) { $type = dig_current_post_type(); } $class = str_replace('dig_', '', $type); $class = str_replace('_', '-', $class); return $class; } https://gist.github.com/onishiweb/9151992
  10. @onishiweb Add better classes function dig_current_post_type() { global $post; if(

    ! is_tag() ) { $type_name = get_post_type(); if( ! $type_name ) { $taxonomy = get_query_var( 'taxonomy' ); $type_name = substr_replace($taxonomy, '', -9); } return $type_name; } } https://gist.github.com/onishiweb/9152009
  11. @onishiweb Better classes = Happy Adam! <!-- Post type archive

    page --> <body class="archive post-type-archive post-type-archive-dig_product product"> <!-- Taxonomy archive --> <body class="archive tax- dig_product_filter_2 term-detergent term-114 product">
  12. @onishiweb Biggest lesson learnt from this current project: WordPress plugins

    are largely evil, and should not be relied on for core functionality - Alex Jegtnes (@jegtnes)