SlideShare une entreprise Scribd logo
1  sur  28
An Introduction to Hooks
An exploration into everyone’s favourite
useless WordPress plugin - Hello Dolly
“This sounds like it might be useful!”
“…huh?”
“…huh?”
• WordPress ships with a simple plugin named
“Hello Dolly”
• Its name is a whimsical take on the
programmer's obligatory “Hello, World!”
• It’s trotted out only for pedantic programming
explanations like the one that you’re about to sit
through…
“Wow, that’s really useful!” said no one ever…
The Code
“…huh?”
WordPress Hooks
• A “hook” is a WordPress Event
• Hooks are provided by WordPress to allow
your plugin to “hook into” the rest of
WordPress; that is, to call functions in your
plugin at specific times, and thereby set your
plugin in motion.
WordPress Hooks
• As a WordPress post is loaded, each hook is
run in a specific order
• There are two types of hooks:
• Actions – adds functionality
• Filters – changes functionality
WordPress Actions
We just saw two “Actions” in action:
• add_action( 'admin_notices', 'hello_dolly' );
• add_action( 'admin_head', 'dolly_css' );
WordPress Actions
Let’s replace this:
• add_action( 'admin_notices', 'hello_dolly' );
With this:
• add_action( 'admin_footer', 'hello_dolly' );
WordPress Actions
What if we ran them together?
• add_action( 'admin_notices', 'hello_dolly' );
• add_action( 'admin_footer', 'hello_dolly' );
Would the output be the same?
WordPress Filters
Let’s replace this:
• add_action( 'admin_notices', 'hello_dolly' );
With this:
• add_filter( ’the_content', 'hello_dolly' );
WordPress Filters
WordPress Filters
Let’s edit the hello_dolly() function so it accepts
an input, and returns the input plus the lyric:
function hello_dolly($input) {
$chosen = hello_dolly_get_lyric();
return $input . "<p id='dolly'>$chosen</p>”;
}
WordPress Filters
Real World Examples
Register a Custom Menu in the Admin
function register_my_custom_menu_page() {
add_menu_page( 'custom menu title', 'custom menu',
'manage_options', 'myplugin/myplugin-admin.php', '', 'dashicons-admin-
site', 6 );
}
add_action( 'admin_menu', 'register_my_custom_menu_page' );
Real World Examples
Hook into Post Publishing
function publish_post_tweet($post_ID) {
global $post;
// Code to send a tweet with post info
}
add_action('publish_post', 'publish_post_tweet');
Real World Examples
Hook Into Widget Initialization
function create_my_widget() {
register_sidebar(array(
'name' => __( 'My Sidebar', 'mytheme' ),
'id' => 'my_sidebar',
'description' => __( 'The one and only', 'mytheme' ),
));
}
add_action( 'widgets_init', 'create_my_widget' );
Real World Examples
Hook Into Front-end Scripts and Styles
function theme_styles() {
wp_enqueue_style( 'bootstrap_css', get_template_directory_uri() . '/css/bootstrap.min.css' );
wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css' );
wp_enqueue_script( 'bootstrap_js', get_template_directory_uri() . '/js/bootstrap.min.js',
array('jquery'), '', true );
wp_enqueue_script( 'theme_js', get_template_directory_uri() . '/js/theme.js', array('jquery',
'bootstrap_js'), '', true );
}
add_action( 'wp_enqueue_scripts', 'theme_styles' );
WordPress Wishlist?
Have you ever thought to yourself “This WordPress
thing is pretty good, but it would be amazing if it
did ‘x’…”

Contenu connexe

Tendances

PowerShell Script to add multiple users to a group in AD
PowerShell Script to add multiple users to a group in ADPowerShell Script to add multiple users to a group in AD
PowerShell Script to add multiple users to a group in AD
Joseph Daramola
 
Artdm170 Week4 Java Script Effects
Artdm170 Week4 Java Script EffectsArtdm170 Week4 Java Script Effects
Artdm170 Week4 Java Script Effects
Gilbert Guerrero
 
Mume JQueryMobile Intro
Mume JQueryMobile IntroMume JQueryMobile Intro
Mume JQueryMobile Intro
Gonzalo Parra
 
Desymfony 2011 - Habemus Bundles
Desymfony 2011 - Habemus BundlesDesymfony 2011 - Habemus Bundles
Desymfony 2011 - Habemus Bundles
Albert Jessurum
 
Jquery Best Practices
Jquery Best PracticesJquery Best Practices
Jquery Best Practices
brinsknaps
 
Sprout core and performance
Sprout core and performanceSprout core and performance
Sprout core and performance
Yehuda Katz
 
Using shortcode in plugin development
Using shortcode in plugin developmentUsing shortcode in plugin development
Using shortcode in plugin development
gskhanal
 
Automated Tests and CSS
Automated Tests and CSSAutomated Tests and CSS
Automated Tests and CSS
klamping
 
20111014 mu me_j_querymobile
20111014 mu me_j_querymobile20111014 mu me_j_querymobile
20111014 mu me_j_querymobile
Erik Duval
 

Tendances (20)

PowerShell Script to add multiple users to a group in AD
PowerShell Script to add multiple users to a group in ADPowerShell Script to add multiple users to a group in AD
PowerShell Script to add multiple users to a group in AD
 
jQuery
jQueryjQuery
jQuery
 
HelloWorld
HelloWorldHelloWorld
HelloWorld
 
Automating boring tasks with Powershell
Automating boring tasks with PowershellAutomating boring tasks with Powershell
Automating boring tasks with Powershell
 
Artdm170 Week4 Java Script Effects
Artdm170 Week4 Java Script EffectsArtdm170 Week4 Java Script Effects
Artdm170 Week4 Java Script Effects
 
Assetic (OSCON)
Assetic (OSCON)Assetic (OSCON)
Assetic (OSCON)
 
Mume JQueryMobile Intro
Mume JQueryMobile IntroMume JQueryMobile Intro
Mume JQueryMobile Intro
 
Desymfony 2011 - Habemus Bundles
Desymfony 2011 - Habemus BundlesDesymfony 2011 - Habemus Bundles
Desymfony 2011 - Habemus Bundles
 
Jquery Best Practices
Jquery Best PracticesJquery Best Practices
Jquery Best Practices
 
Sprout core and performance
Sprout core and performanceSprout core and performance
Sprout core and performance
 
Using shortcode in plugin development
Using shortcode in plugin developmentUsing shortcode in plugin development
Using shortcode in plugin development
 
Webapps without the web
Webapps without the webWebapps without the web
Webapps without the web
 
Automated Tests and CSS
Automated Tests and CSSAutomated Tests and CSS
Automated Tests and CSS
 
20111014 mu me_j_querymobile
20111014 mu me_j_querymobile20111014 mu me_j_querymobile
20111014 mu me_j_querymobile
 
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
 
Assetic (Zendcon)
Assetic (Zendcon)Assetic (Zendcon)
Assetic (Zendcon)
 
Hello world
Hello worldHello world
Hello world
 
Hack U - YUI - 2012 IIT Kharagpur
Hack U - YUI - 2012 IIT KharagpurHack U - YUI - 2012 IIT Kharagpur
Hack U - YUI - 2012 IIT Kharagpur
 
Take Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksTake Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorks
 
Theming Wordpress with Adobe
Theming Wordpress with AdobeTheming Wordpress with Adobe
Theming Wordpress with Adobe
 

Similaire à An Introduction to WordPress Hooks

Plug in development
Plug in developmentPlug in development
Plug in development
Lucky Ali
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
arcware
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
Yoav Farhi
 
Bending word press to your will
Bending word press to your willBending word press to your will
Bending word press to your will
Tom Jenkins
 

Similaire à An Introduction to WordPress Hooks (20)

Plug in development
Plug in developmentPlug in development
Plug in development
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress Developer
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?
 
WordPress: Adding user-role
WordPress: Adding user-roleWordPress: Adding user-role
WordPress: Adding user-role
 
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress Plugin
 
Как получить чёрный пояс по WordPress? v2.0
Как получить чёрный пояс по WordPress? v2.0Как получить чёрный пояс по WordPress? v2.0
Как получить чёрный пояс по WordPress? v2.0
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
 
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
 
Hooking with WordPress
Hooking with WordPressHooking with WordPress
Hooking with WordPress
 
Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin Development
 
How To Write a WordPress Plugin
How To Write a WordPress PluginHow To Write a WordPress Plugin
How To Write a WordPress Plugin
 
Jumping Into WordPress Plugin Programming
Jumping Into WordPress Plugin ProgrammingJumping Into WordPress Plugin Programming
Jumping Into WordPress Plugin Programming
 
Introduction to WordPress Development - Hooks
Introduction to WordPress Development - HooksIntroduction to WordPress Development - Hooks
Introduction to WordPress Development - Hooks
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
 
Cain & Obenland — Episode 4
Cain & Obenland — Episode 4Cain & Obenland — Episode 4
Cain & Obenland — Episode 4
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
 
Bending word press to your will
Bending word press to your willBending word press to your will
Bending word press to your will
 
WordPress plugin #2
WordPress plugin #2WordPress plugin #2
WordPress plugin #2
 
Actions filters
Actions filtersActions filters
Actions filters
 

Plus de Andrew Marks

Plus de Andrew Marks (13)

Wordpress for Business
Wordpress for BusinessWordpress for Business
Wordpress for Business
 
Google Analytics Essential Training
Google Analytics Essential TrainingGoogle Analytics Essential Training
Google Analytics Essential Training
 
Learn to Think Like a Coder
Learn to Think Like a CoderLearn to Think Like a Coder
Learn to Think Like a Coder
 
Why Code Is Cool (And Why You Should Learn It)
Why Code Is Cool (And Why You Should Learn It)Why Code Is Cool (And Why You Should Learn It)
Why Code Is Cool (And Why You Should Learn It)
 
A Guide to Google My Business
A Guide to Google My BusinessA Guide to Google My Business
A Guide to Google My Business
 
How WordPress Sites Get Hacked
How WordPress Sites Get HackedHow WordPress Sites Get Hacked
How WordPress Sites Get Hacked
 
An Introduction to Gutenberg, WordPress's New Editor
An Introduction to Gutenberg, WordPress's New EditorAn Introduction to Gutenberg, WordPress's New Editor
An Introduction to Gutenberg, WordPress's New Editor
 
Processing Client Payments from your WordPress Website
Processing Client Payments from your WordPress WebsiteProcessing Client Payments from your WordPress Website
Processing Client Payments from your WordPress Website
 
GDPR - What You Need To Know
GDPR - What You Need To KnowGDPR - What You Need To Know
GDPR - What You Need To Know
 
10 Tips for Optimising WordPress
10 Tips for Optimising WordPress10 Tips for Optimising WordPress
10 Tips for Optimising WordPress
 
An (Updated) Introduction to Gutenberg
An (Updated) Introduction to GutenbergAn (Updated) Introduction to Gutenberg
An (Updated) Introduction to Gutenberg
 
Ultimate Guide to WordPress Multisite
Ultimate Guide to WordPress MultisiteUltimate Guide to WordPress Multisite
Ultimate Guide to WordPress Multisite
 
Ultimate Guide to Advanced Custom Fields
Ultimate Guide to Advanced Custom FieldsUltimate Guide to Advanced Custom Fields
Ultimate Guide to Advanced Custom Fields
 

Dernier

Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Chandigarh Call girls 9053900678 Call girls in Chandigarh
 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 

Dernier (20)

Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
 
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
 
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort ServiceBusty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
 
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceReal Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
 

An Introduction to WordPress Hooks

  • 2. An exploration into everyone’s favourite useless WordPress plugin - Hello Dolly
  • 3. “This sounds like it might be useful!”
  • 5. “…huh?” • WordPress ships with a simple plugin named “Hello Dolly” • Its name is a whimsical take on the programmer's obligatory “Hello, World!” • It’s trotted out only for pedantic programming explanations like the one that you’re about to sit through…
  • 6.
  • 7. “Wow, that’s really useful!” said no one ever…
  • 10.
  • 11.
  • 12.
  • 13. WordPress Hooks • A “hook” is a WordPress Event • Hooks are provided by WordPress to allow your plugin to “hook into” the rest of WordPress; that is, to call functions in your plugin at specific times, and thereby set your plugin in motion.
  • 14.
  • 15.
  • 16. WordPress Hooks • As a WordPress post is loaded, each hook is run in a specific order • There are two types of hooks: • Actions – adds functionality • Filters – changes functionality
  • 17. WordPress Actions We just saw two “Actions” in action: • add_action( 'admin_notices', 'hello_dolly' ); • add_action( 'admin_head', 'dolly_css' );
  • 18. WordPress Actions Let’s replace this: • add_action( 'admin_notices', 'hello_dolly' ); With this: • add_action( 'admin_footer', 'hello_dolly' );
  • 19. WordPress Actions What if we ran them together? • add_action( 'admin_notices', 'hello_dolly' ); • add_action( 'admin_footer', 'hello_dolly' ); Would the output be the same?
  • 20. WordPress Filters Let’s replace this: • add_action( 'admin_notices', 'hello_dolly' ); With this: • add_filter( ’the_content', 'hello_dolly' );
  • 22. WordPress Filters Let’s edit the hello_dolly() function so it accepts an input, and returns the input plus the lyric: function hello_dolly($input) { $chosen = hello_dolly_get_lyric(); return $input . "<p id='dolly'>$chosen</p>”; }
  • 24. Real World Examples Register a Custom Menu in the Admin function register_my_custom_menu_page() { add_menu_page( 'custom menu title', 'custom menu', 'manage_options', 'myplugin/myplugin-admin.php', '', 'dashicons-admin- site', 6 ); } add_action( 'admin_menu', 'register_my_custom_menu_page' );
  • 25. Real World Examples Hook into Post Publishing function publish_post_tweet($post_ID) { global $post; // Code to send a tweet with post info } add_action('publish_post', 'publish_post_tweet');
  • 26. Real World Examples Hook Into Widget Initialization function create_my_widget() { register_sidebar(array( 'name' => __( 'My Sidebar', 'mytheme' ), 'id' => 'my_sidebar', 'description' => __( 'The one and only', 'mytheme' ), )); } add_action( 'widgets_init', 'create_my_widget' );
  • 27. Real World Examples Hook Into Front-end Scripts and Styles function theme_styles() { wp_enqueue_style( 'bootstrap_css', get_template_directory_uri() . '/css/bootstrap.min.css' ); wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css' ); wp_enqueue_script( 'bootstrap_js', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), '', true ); wp_enqueue_script( 'theme_js', get_template_directory_uri() . '/js/theme.js', array('jquery', 'bootstrap_js'), '', true ); } add_action( 'wp_enqueue_scripts', 'theme_styles' );
  • 28. WordPress Wishlist? Have you ever thought to yourself “This WordPress thing is pretty good, but it would be amazing if it did ‘x’…”