It’s actually used by WP to allow plugin developers change WP behavior. You can make your code flexible using do_action so other plugin/theme developers or simply yourself can change behavior of your code.
For example imagine you have a WP loop in a theme framework. You would like to add breadcrumb at the top of it, here is the simplest method:
...
<?php print_breadcrumb(); ?>
<h2><?php the_title(); ?></h2>
...
But this way plugin developers or site authors require to edit print_breadcrumb() at functions.php to add their own breadcrumbs. Better way is using do_action()
...
<?php do_action('breadcrumb') ?>
<h2><?php the_title(); ?></h2>
...
Now you can add this in functions.php to get same behavior:
add_action('breadcrumb', 'print_breadcrumb');
Now a plugin author may override your code by:
add_action('breadcrumb', 'their_own_breadcrumb');
Related Posts:
- How to remove the Theme Customization Button from the dashboard and themes options page?
- Display a different theme for not logged-in users
- Get password when user registers and save it sha1 into database
- Passing variable in hooks and filter
- Highlight “Show all” item in wp_list_categories
- Menu item added in wp_nav_menu_items filter is never highlighted
- Pass variable to hook. Its possible?
- How to change footer credit text in Twenty Twenty One theme with a hook?
- Modify available templates (in dropdown)
- WordPress wp_get_current_user returning blank values until refresh
- Is there any filter or action hook to remove layout classes from appearing in my templates?
- get_template_part vs action hooks in themes
- Theme Activate Hook
- Issues with title-tag and document_title_parts
- Add custom classes to anchor in wp_nav_menu
- What filters are applied to the_content function?
- Change admin bar to default:off
- How to modify an image block in Gutenberg WordPress 5?
- Edit srcset and sizes attributes in Gutenberg image, cover and gallery – blocks
- Getting instance variable in scope of ‘wp_enqueue_scripts’
- wp_get_attachment_image_attributes not working for me
- How do I Make a Theme “plugin-ready”?
- What can I hook into after_setup_theme?
- Run shortcode before filters
- Add class to before_widget for all widgets with a dropdown and a counter
- How to Auto Approve Comments on a Specific Page?
- Identifying the priority of style.css so I can make a small CSS file load last
- What’s the difference between hooks, filters and actions? [duplicate]
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- How do I “unhook” / de-register jQuery so that it’s not called as part of wp_footer();?
- wp_enqueue_scripts not called on search page?
- WordPress nav_menu_css_class theme filter is not being called
- customizing the_password_form filter
- WordPress Genesis Child Theme Filter divs
- Change file name from wp_generate_attachment_metadata
- Creating multiple hooks for theme
- How to add theme support?
- Simple way to get two language WP site
- Should I use function_exists() and/or add_action() in theme development?
- When trying to override plugin’s function by theme, my filter executes two times, I want it to run only a single time
- Injecting a custom sql query into a page/theme
- Single-level menu option? Another way?
- Should I use add_filter for functions in function.php of the theme?
- How to change database values on theme update
- What is the “correct” way to add hooks or similar PHP behavior to a blocktheme?
- Show notice just below the search form on the themes page
- Default image size not working
- Theme Development: Starter Content after hook
- WordPress taxonomy and archive custom class
- WordPress custom taxonomy check box to dropdown
- Filter categories used with Custom Structure Permalink
- Theme Customizer not loading JS for live preview
- Dynamic menu links after header title
- How to wrap all titles generated by Gutenberg “Heading” block with tag
- What are the hooks in WordPress theme development?
- Replace single_template filter with what for default posts?
- Unique design inside a specific category’s url
- How to rotate every letter in a title
- How to disable thumbnail filter for a specific template part or image size?
- CSS class on last post in loop ( custom query )
- Use a filter on menu items that have children
- Difference between “comment_form_default_fields” AND “comment_form_fields”
- Is There A WordPress Hook for Accessing Attachments for A Particular Page?
- tiny_mce_before_init: ‘exact’ => true has no effect
- pre_get_comments or the_content filter
- How to conditionally add a wp_filter
- Add content after get_header
- Filter didn’t work on content class (hybrid_post_attributes)
- How to set default values for edit_post_link() in my theme?
- Tiny MCE custom styles, and preview in the backend
- content filter (add_filter) for category description?
- Related Post Category Filter
- Pagination don’t work with active filters
- How to register dynamic settings in WordPress Customizer?
- restrain filter on get_the_excerpt to queried item in stead of current post
- Unpublished Pages Failing To Appear On Custom Path
- Put CSS Content inside tag for WordPress
- Alternative solution for script_loader_tag?
- Alt header logo and link for specific pages
- WordPress Twenty-Fourteen: How to Remove Home Page Header Image from Other Pages
- How to hook into wordpress upgrade procedure for a custom theme
- Alter theme pages on language switch
- Make a custom field in admin post.php read only
- Hook in parent theme Menu function
- How do I remove p tag *insertions*? Disabling `wpautop` removes manual tags
- How to add custom nav_menu_css_class to certain menu only?
- How to manipulate wordpress template tags’ output
- Suppress the_content filter in a nested loop
- apply_filters to featured image
- Add rel to all images in a post
- Add text when displying attribute with a hook on single product page
- How to hook wp_list_pages?
- How do the default themes reference style.css?
- Input ordering in wordpress theme customizer
- Add content as soon starts
- Overide enqueue in non plugable function via child theme
- How to safely return the HTML?
- Hide/disable sidebar using shortcode?
- Where are the options “template” and “current_theme” derived from
- A Reviews Page is Showing root Index.php instead of Template-Page