-
-
----2021-06-07 19:41:15
WordPress
----, 2021-06-07 19:41:15

Why does the action hook work, which is not in the documentation?

Hello! I'm getting into Wordpress and writing simple plugins... At the moment I'm smoking the topic of "hooks"... The
question arose:
1) we have filter the_title (namely, filter, this is important... dock
from the documentation:

apply_filters( 'the_title', string $title, int $id )

2) there is a simple plugin
// код плагина
add_action('the_title', 'my_function');
function my_function($title){

  $mytitle = $title.'-суффикс';
  return $mytitle;
}
//do_action('the_title');

Now, attention to the question:
1) why does it work through add_action (and not through apply_filters, as stated in the doc)
2) why does it work without calling do_action?
I want to understand all this magic...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Druzhaev, 2021-06-10
@stalkerxxl

Because add_action is the same as add_filter with one peculiarity - the first one does not return anything, and the filter must return the first argument

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question