Please explain me what the do_action does

If you hook some functions to the before_sidebar action, they will be executed in your code. Your action is now probably without any function hooked, so it returns nothing.

Example:

<?php
add_action( 'before_sidebar', function() {
  echo 'Try me!';
});
add_action( 'before_sidebar', function() {
  echo 'Yep. ';
}, 1);

// this should output "Yep. Try me!"
<?php do_action( 'before_sidebar' ); ?>

The third argument is a priority. In my example I’ve set the priority to 1 to the second function and it will be executed at first place.

For more information take a look at WP Codex do_action, and add_action.

Leave a Comment