Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Introduction to Wordpress Hooks

105 vues

Publié le

My slides for the Bristol Wordpress People talk https://www.meetup.com/wpbristol/events/kfmbspyxjbhb/

Publié dans : Internet
  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

Introduction to Wordpress Hooks

  1. 1. An Introduction to WordPress Hooks Actions and Filters Anthony Hartnell @assemblrTech
  2. 2. What are Hooks?
  3. 3. What are Hooks? •Hooks are WordPress functions that are used to modify or add functionality
  4. 4. What are Hooks? •A way for you to change the default behaviour of Wordpress. •Hooks are WordPress functions that are used to modify or add functionality
  5. 5. There are 2 Types of Hooks:
  6. 6. Actions There are 2 Types of Hooks:
  7. 7. Filters There are 2 Types of Hooks: Actions
  8. 8. Actions Functions that are executed when something happens in WordPress.
  9. 9. For example: • When a post is published • Before the header is loaded Declared with add_action Actions Functions that are executed when something happens in WordPress.
  10. 10. You can attach custom code at these events: Actions Functions that are executed when something happens in WordPress.
  11. 11. You can attach custom code at these events: • When a post is published, send me an email Actions Functions that are executed when something happens in WordPress.
  12. 12. You can attach custom code at these events: • When a post is published, send me an email • Before the header is loaded, insert an image Actions Functions that are executed when something happens in WordPress.
  13. 13. Functions that WordPress passes data through before it is sent to the browser or database. Filters
  14. 14. For example: • When the post title is displayed • When the author url is output Declared with add_filter Functions that WordPress passes data through before it is sent to the browser or database. Filters
  15. 15. Functions that WordPress passes data through before it is sent to the browser or database. Filters You can attach custom code at these events:
  16. 16. Functions that WordPress passes data through before it is sent to the browser or database. Filters You can attach custom code at these events: • When the post title is displayed, add the date
  17. 17. Functions that WordPress passes data through before it is sent to the browser or database. Filters You can attach custom code at these events: • When the post title is displayed, add the date • When the author url is output, redirect it to google
  18. 18. Which Hook should I use? Actions FiltersOR
  19. 19. Which Hook should I use? Actions FiltersOR Use an action when you want something to happen
  20. 20. Which Hook should I use? Actions FiltersOR Use an action when you want something to happen Use a filter when you want to change something
  21. 21. Header Content Footer Theme Structure
  22. 22. Header Content Footer Theme Structure Before header Before content After content
  23. 23. Header Content Footer Theme Structure Before header Before content After content
  24. 24. Header Content Footer Theme Structure Before header Before content Add some text after the post title Change the site tagline After content
  25. 25. Header Content Footer Theme Structure Before header Before content Change the site tagline After content Add some text after the post title
  26. 26. Info about hooks https://codex.wordpress.org/Plugin_API Example Actions wp_enqueue_scripts create_category publish_page the_title excerpt_more the_content Example Filters
  27. 27. How to construct a hook
  28. 28. How to construct a hook tag - the name of the action to attach code to your_function - the name of your custom function $priority - the order that the functions are executed $args - the number of arguments sent to your function
  29. 29. Breaking it down
  30. 30. Live Coding Demonstration 😅
  31. 31. Questions Anthony Hartnell @assemblrTech Any questions, email anthony@atomicsmash.co.uk

×