0
How I Became a WordPress
Hacker
Mike Zielonka
@mikezielonka
Co-Founder and Director of Web Strategy
At Tuna Traffic
Loves Pizza, Dogs, More Pizza and Coffee
I Am Mike Zielonka
What We’ll Cover
● Why the struggle is part of the journey
● The basics of using Actions & Filters
● How to make a plugin ...
Successful WordPress Hackers Can...
Customize WordPress Themes and Plugins
without writing a lot of code.
The Struggle Is…
● PHP is scary
● Making your own plugin is scary
● PHP is very scary
● You just never have the options yo...
My Journey
2011 Mike “The SEO”
2012 Mike “Frameworks”
2013 Mike “The Hacker”
2014 Mike “Expert Generalist”
Whats a Hook According to the Codex
“Hooks are specified, by the developer, in
Actions and Filters. “
“In technical and st...
Where do Hooks Live
Generally speaking, you have 3 different
places where “hooks” live.
● Core
● Themes
● Plugins
Allows you to “do something” to insert
something at a “checkpoint”.
Action Defined
Action Example
add_action( ‘wp_head’, ‘wc_your_function_name’ );
function wc_your_function_name() {
?>
<!--hi people-->
<?...
add_action
add_action( ‘wp_head’, ‘wc_your_function_name’ );
Where You Hook In What To Add
Adding What You Want (Writing a Function)
function wc_your_function_name() {
?>
<!--hi people-->
<?php
}
Your function nam...
Real Life Example
//Adding A Credit Link to TwentyFourteen
add_action( 'twentyfourteen_credits' , 'mz_site_credits'
);
fun...
Allows you to “filter the result” and return
something different at a “fancy checkpoint”.
Filter
Filter Example
add_filter( ‘wp_title’,
‘wc_your_function_filter_name’, 10, 2 );
function wc_your_function_filter_name($tit...
add_filter
add_filter( ‘wp_title’,‘wc_your_function_filter_name’, 10,
2 );
Where You Hook In What To Add
Priority
Accepted...
Returning What You Want (Writing a Function)
function wc_your_function_filter_name($title, $sep)
{
$name = ‘My Site is Cal...
Real Life Example
//Adding a Phrase the Site Title
add_filter( 'wp_title', 'wc_your_function_filter_name', 10, 2 );
functi...
Where To Put Your Hooks
● Functions.php of your theme
○ Preferably in a child theme
● Plugin
Adding Hooks To A Plugin
Add Opening PHP Tag and Add A Plugin Header
<?php
/*
Plugin Name: Mike's Sample Plugin
Plugin URI...
Putting It All Together
Basic Rookie Tips
● Namespace your functions to avoid
conflicts. ie: mz_function
● Do not start functions with numbers.
● ...
Helpful Tools
For Hooking Efficiently
Google
Debug Bar w/ Debug Bar Actions and Filters Addon
Searching for Actions in Sublime Text 3
Follow Me On Twitter
@mikezielonka
Thank You
Upcoming SlideShare
Loading in...5
×

How I Became a WordPress Hacker

446

Published on

A talk given at WordCamp Milwaukee on how to use WordPress Hooks called: Actions and Filters to become a WordPress Hacker.

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
446
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
4
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "How I Became a WordPress Hacker"

  1. 1. How I Became a WordPress Hacker Mike Zielonka @mikezielonka
  2. 2. Co-Founder and Director of Web Strategy At Tuna Traffic Loves Pizza, Dogs, More Pizza and Coffee I Am Mike Zielonka
  3. 3. What We’ll Cover ● Why the struggle is part of the journey ● The basics of using Actions & Filters ● How to make a plugin for your Hooks
  4. 4. Successful WordPress Hackers Can... Customize WordPress Themes and Plugins without writing a lot of code.
  5. 5. The Struggle Is… ● PHP is scary ● Making your own plugin is scary ● PHP is very scary ● You just never have the options you need
  6. 6. My Journey 2011 Mike “The SEO” 2012 Mike “Frameworks” 2013 Mike “The Hacker” 2014 Mike “Expert Generalist”
  7. 7. Whats a Hook According to the Codex “Hooks are specified, by the developer, in Actions and Filters. “ “In technical and strict terms: a Hook is an event, i.e. event as understood by Observer pattern, invoked by the do_action() or apply_filters() call that afterwards triggers all the action or filter functions, previously hooked to that event using add_action() or add_filter(), respectively.”
  8. 8. Where do Hooks Live Generally speaking, you have 3 different places where “hooks” live. ● Core ● Themes ● Plugins
  9. 9. Allows you to “do something” to insert something at a “checkpoint”. Action Defined
  10. 10. Action Example add_action( ‘wp_head’, ‘wc_your_function_name’ ); function wc_your_function_name() { ?> <!--hi people--> <?php }
  11. 11. add_action add_action( ‘wp_head’, ‘wc_your_function_name’ ); Where You Hook In What To Add
  12. 12. Adding What You Want (Writing a Function) function wc_your_function_name() { ?> <!--hi people--> <?php } Your function name PHP On and Off Your HTML
  13. 13. Real Life Example //Adding A Credit Link to TwentyFourteen add_action( 'twentyfourteen_credits' , 'mz_site_credits' ); function mz_site_credits() { echo "<a href='http://iammike.co' title='mike zielonka'>Designed by Mike Zielonka</a>"; }
  14. 14. Allows you to “filter the result” and return something different at a “fancy checkpoint”. Filter
  15. 15. Filter Example add_filter( ‘wp_title’, ‘wc_your_function_filter_name’, 10, 2 ); function wc_your_function_filter_name($title, $sep) { $name = ‘My Site is Called ’; $title .= $sep . ' ' . $name; return $title; }
  16. 16. add_filter add_filter( ‘wp_title’,‘wc_your_function_filter_name’, 10, 2 ); Where You Hook In What To Add Priority Accepted Arguments
  17. 17. Returning What You Want (Writing a Function) function wc_your_function_filter_name($title, $sep) { $name = ‘My Site is Called ’; $title .= $sep . ' ' . $name; return $title; } Your function name Return your changes Arguments
  18. 18. Real Life Example //Adding a Phrase the Site Title add_filter( 'wp_title', 'wc_your_function_filter_name', 10, 2 ); function wc_your_function_filter_name($title, $sep) { $name = 'My Site is Called '; $title .= $sep . ' ' . $name; return $title; }
  19. 19. Where To Put Your Hooks ● Functions.php of your theme ○ Preferably in a child theme ● Plugin
  20. 20. Adding Hooks To A Plugin Add Opening PHP Tag and Add A Plugin Header <?php /* Plugin Name: Mike's Sample Plugin Plugin URI: Description: Adds some sample hooks. Author: Mike Zielonka Version: 1.0 Author URI: http://iammike.co Text Domain: mz-sample-plugin */
  21. 21. Putting It All Together
  22. 22. Basic Rookie Tips ● Namespace your functions to avoid conflicts. ie: mz_function ● Do not start functions with numbers. ● Always take back ups. ● Learn more about the PHP function function_exists() to prevent headaches when switching themes and plugins
  23. 23. Helpful Tools For Hooking Efficiently
  24. 24. Google
  25. 25. Debug Bar w/ Debug Bar Actions and Filters Addon
  26. 26. Searching for Actions in Sublime Text 3
  27. 27. Follow Me On Twitter @mikezielonka Thank You
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×