I’m a newbie in WordPress and I need a big help to understand how do-action works.
It seems there is a relationship between the instruction do_action
and the code that follows it in the get_xxx function that I don’t understand. For example, in the following function :
function get_header( $name = null ) {
do_action( 'get_header', $name );
$templates = array();
$name = (string) $name;
if ( '' !== $name ) {
$templates[] = "header-{$name}.php"; // instruction 1
}
$templates[] = 'header.php'; // instruction 2
locate_template( $templates, true );
}
There is a do_action
at the beginning to find header.php
. Then afterwards, a series of codes are doing the same thing but with likely an issue because the content of the variable $templates
of the line “instruction 1” is always overridden by the one in the line of “instruction 2” because it is not a “if then else”.
In every function get_xxxx we have the same structure. I guess there is a relationship between the do_action
call and the series of codes that follow but I don’t get it.
I will be very grateful if somebody can help me to understand this issue.