Wordpress Theme Hacks

download Wordpress Theme Hacks

of 33

Transcript of Wordpress Theme Hacks

  • 8/8/2019 Wordpress Theme Hacks

    1/33

    Wordpress Theme Hacks NearlyAnyone Can Do

    Afraid you might "breaksomething" by muckingaround in your theme? Witha little determination, and justa few keystrokes - you'd besurprised how many thingsyou can change on your own.

  • 8/8/2019 Wordpress Theme Hacks

    2/33

    How I Met Wordpress

    THIS WAS MEFor10 LONG YEARS

  • 8/8/2019 Wordpress Theme Hacks

    3/33

    In 1999 I was hired as a webmaster

    I was VERY loyal

  • 8/8/2019 Wordpress Theme Hacks

    4/33

    Webmasters Did Everything

    HTML

    Javascript

    Graphics

    Technical Writing

    CGI/Perl Coding

    UNIX Shell Coding Create Online Tools

    Training

  • 8/8/2019 Wordpress Theme Hacks

    5/33

    Open Source CMS

    I tried to introduce multiple Open Source CMSSystems to Automate my Job

  • 8/8/2019 Wordpress Theme Hacks

    6/33

    Big Money Always Won

  • 8/8/2019 Wordpress Theme Hacks

    7/33

    I Met Wordpress in 2004

  • 8/8/2019 Wordpress Theme Hacks

    8/33

    I Thought They Were Wrong...

    So I kept using Wordpress on My Own...

    Sometimes instead ofdoing my real work.

  • 8/8/2019 Wordpress Theme Hacks

    9/33

    Little Did I Know...

    In 2009 they outsourced the last of us...the last of the webmasters that is.

  • 8/8/2019 Wordpress Theme Hacks

    10/33

    I Was Out of Work

    No Jobs. Unemployment.Couldn't Move.

    What Now?

  • 8/8/2019 Wordpress Theme Hacks

    11/33

    Reinvention

  • 8/8/2019 Wordpress Theme Hacks

    12/33

    Wordpress Theme Hacks Nearly

    Anyone Can DoYou Will Need to:

    Use the Wordpressdashboard editor

    Know basic HTML

    Be able to Edit, Copy

    and Paste smallamounts of PHPCode

  • 8/8/2019 Wordpress Theme Hacks

    13/33

    Why Hack a Wordpress Theme?

    To stand out or look differentcreate a look nobody else hasTo add functionality for the end user

    like, tweet, disqusTo enhance the way content is displayed

    post meta, text, images, the_loop, navigationTo customize specific pages

    search results, 404 Pages, archives, category & tags pagesTo show content only when conditions are met

    only on the home page, just singles posts, only tag pages,etc.

  • 8/8/2019 Wordpress Theme Hacks

    14/33

    How Do I Edit My WP Theme?

    In WP dashboard: Appearance EditorClick on the page you want to edit:

  • 8/8/2019 Wordpress Theme Hacks

    15/33

    What Are All Those Theme Pages?

    At Bare Minimum, Most WP Themes Have:index.php (home page + a whole lot more)single.php (single posts)page.php (paged pages like your about page)comments.php (the comments block after content)header.php (before the content on EVERY page)footer.php (after the content on EVERY page)sidebar.php (what's in the sidebar)functions.php (special theme specific PHP code)style.css (text formatting and layout rules)

    Reference: http://codex.wordpress.org/Template_Hierarchy

    http://codex.wordpress.org/Template_Hierarchyhttp://codex.wordpress.org/Template_Hierarchy
  • 8/8/2019 Wordpress Theme Hacks

    16/33

    Which file does what?

    A page file (index, single, page) calls and loadsother files for specific page content areas:

  • 8/8/2019 Wordpress Theme Hacks

    17/33

    How Many Pages Could MyWP Theme Have?

    The Bare Minimum

    index.php

    single.php

    page.php

    comments.php

    header.php

    footer.php

    functions.php

    sidebar.php

    style.css

    Optional Theme Pages

    archive.php (date based archives)

    search.php (search results)

    category.php (category pages)

    tag.php (tag pages)

    404.php (not found errors)

    attachment.php (attachments)

    author.php (author page)

    loop.php (Wordpress 3.0+)

    Countless custom template files

  • 8/8/2019 Wordpress Theme Hacks

    18/33

    Why Use Conditional Tags

    To do something only whencertain conditions are met

    Examples:

    Show specific text or images Create custom adverts for specific uses

    Designate alternate layouts for certain pages

    Using plugins to do this slows down your site

  • 8/8/2019 Wordpress Theme Hacks

    19/33

    Where can I use Conditional Tags?

    Conditions such as is_home with is_front_page, is_single,is_sticky, is_page, is_page_template, is_category,is_tag, is_author, work great in sections such as:

    index.php

    Header or Footer

    Sidebars

    the_loop

    Comments block

  • 8/8/2019 Wordpress Theme Hacks

    20/33

    Very Specific Conditions

    Specify individual pages like is_single('hello') orin_category('5'), is_page_template('contact.php'),is_tag('ipod') or has_tag('ipod'), is_author('john-pratt'),is_date(), is_single(array('my-best-post', 'my-worst-post'))

    Specific category and tag pages Specific template pages

    Specific archive pages

    Specific post ID's

    Reference the Codex:http://codex.wordpress.org/Conditional_Tags

    http://codex.wordpress.org/Conditional_Tagshttp://codex.wordpress.org/Conditional_Tags
  • 8/8/2019 Wordpress Theme Hacks

    21/33

    Hacking with Conditional Tags

    Do ABC when XYZ Condition is met:

    Show my big block of SEO keyword-laden text

    By replacing is_home with is_front_page, is_single, is_sticky,is_page, is_page_template, is_category, is_tag,is_author, is_date, is_archive, or is_attachment to makeyour message show up on nearly any WordPress page.

  • 8/8/2019 Wordpress Theme Hacks

    22/33

    Having Multiple Conditions

    Do ABC when XYZ Condition is met,elseif single post page do DEF

    Show my home page text blockShow my single post text block instead

    In this example we show custom text for the home page, or onsingle pages. If neither condition is met we don't show anycustom text.

  • 8/8/2019 Wordpress Theme Hacks

    23/33

    Multiple Conditions Else Default

    Do ABC when XYZ Condition is met,elseif single post page do DEF, else show do default

    for all other instances

    Show my home page text block

    Show my single post text block instead

    Show my default text for all other conditions

  • 8/8/2019 Wordpress Theme Hacks

    24/33

    Using Multiple Conditions

    Combine conditions on one statement toshow the same thing in multiple places.

  • 8/8/2019 Wordpress Theme Hacks

    25/33

    Show Everywhere, Except...

    Use the concept in reverse to show everywhereexcept where you don't want it...

    Show this everywhere!

    In this example we show nothing when the home page is shown,else show it every other time.

  • 8/8/2019 Wordpress Theme Hacks

    26/33

    Conditionally Use WP Functions

    Use a Conditional tag to force a WP Function

    Use conditional statements to do things like get_tags, get_category_parents,get_page_children, get_user_meta, and many more...

    Reference: http://codex.wordpress.org/Function_Reference

    http://codex.wordpress.org/Function_Referencehttp://codex.wordpress.org/Function_Reference
  • 8/8/2019 Wordpress Theme Hacks

    27/33

    Hacking Your Comments

    Plugins like subscribe to comments orCommentLuv are great enhancements

    By modifying the text in comments.php, you

    can customize what your comments block says(or how it looks)

    By modifying some of the code, you can add (orremove functionality)

    Get rid of comment spam at the source

    Add D l t d S Li k

  • 8/8/2019 Wordpress Theme Hacks

    28/33

    Add Delete and Spam Linksto Your Comment Sections

    Add this code to your theme's functions.php file:

    function delete_comment_link($id) {if (current_user_can('edit_post')) {echo '| del ';echo '| spam';}

    }

    Add this code to your comments.php where you want the links (usually add itin where you find edit_comment_link()):

    delete_comment_link(get_comment_ID());

    Source:http://www.wprecipes.com/how-to-add-del-and-spam-buttons-to-your-comments

    http://www.wprecipes.com/how-to-add-del-and-spam-buttons-to-your-commentshttp://www.wprecipes.com/how-to-add-del-and-spam-buttons-to-your-comments
  • 8/8/2019 Wordpress Theme Hacks

    29/33

    Stop HTML Links in Comments

    Add this to your functions.php file, all links will be stripped:

    function plc_comment_post( $incoming_comment ) {$incoming_comment['comment_content'] =htmlspecialchars($incoming_comment['comment_content']);$incoming_comment['comment_content'] = str_replace( "'", ''',$incoming_comment['comment_content'] );return( $incoming_comment );

    }

    function plc_comment_display( $comment_to_display ) {$comment_to_display = str_replace( ''', "'", $comment_to_display );return $comment_to_display;}

    add_filter('preprocess_comment', 'plc_comment_post', '', 1);

    add_filter('comment_text', 'plc_comment_display', '', 1);add_filter('comment_text_rss', 'plc_comment_display', '', 1);add_filter('comment_excerpt', 'plc_comment_display', '', 1);

    Reference: http://www.wprecipes.com/how-to-get-rid-of-links-in-your-comments

    http://www.wprecipes.com/how-to-get-rid-of-links-in-your-commentshttp://www.wprecipes.com/how-to-get-rid-of-links-in-your-comments
  • 8/8/2019 Wordpress Theme Hacks

    30/33

    Prevent Most Comment Spam

    Most Spammers use software or scripts that have noreferrer. Require all comments come from a webbrowser to stop the spammers dead!

    Add this to your functions.php file:

    function check_referrer() { if (!isset($_SERVER['HTTP_REFERER']) ||$_SERVER['HTTP_REFERER'] == ) {

    wp_die( __('enable referrers or go away') );}

    }add_action('check_comment_flood','check_referrer');

    Source: http://www.smashingmagazine.com/2009/07/23/10-wordpress-comments-hacks/

    http://www.smashingmagazine.com/2009/07/23/10-wordpress-comments-hacks/http://www.smashingmagazine.com/2009/07/23/10-wordpress-comments-hacks/
  • 8/8/2019 Wordpress Theme Hacks

    31/33

    Hacking Navigation

    Add things to your blog that will make it moreusable and help readers find what they need

    Breadcrumb Plugins

    Related Posts Plugins Most Viewed / Popular Post Plugins

    Category Icons Plugins

  • 8/8/2019 Wordpress Theme Hacks

    32/33

  • 8/8/2019 Wordpress Theme Hacks

    33/33

    Q&A

    Find me:

    facebook.com/jtprattmedia

    www.jtprattmedia.com

    www.jtpratt.com/blog

    twitter.com/jtpratt

    wp-dir.com

    http://www.jtprattmedia.com/http://www.jtpratt.com/bloghttp://www.jtpratt.com/bloghttp://www.jtprattmedia.com/