I'm developing a WordPress plugin for a site that is using the theme ColorMag. The plugin uses the_content()
to insert some content in a page. When I put the plugin in other test site, the content is showing ok, but with the ColorMag theme the content is showing in the right place but also two more times at the start of the page.
Looking at the code I've found that this repeated content is made inside "header.php" in the line <?php do_action( 'colormag_before' ); ?>
. But I can not find where is the corresponding add_action()
so I can not modify it.
Where can I find the add_action()
?
Thanks!
I'm developing a WordPress plugin for a site that is using the theme ColorMag. The plugin uses the_content()
to insert some content in a page. When I put the plugin in other test site, the content is showing ok, but with the ColorMag theme the content is showing in the right place but also two more times at the start of the page.
Looking at the code I've found that this repeated content is made inside "header.php" in the line <?php do_action( 'colormag_before' ); ?>
. But I can not find where is the corresponding add_action()
so I can not modify it.
Where can I find the add_action()
?
Thanks!
Share Improve this question asked Mar 12, 2020 at 8:15 AlbertoAlberto 11 bronze badge2 Answers
Reset to default 2There can be a case that theme implements hooks via do_action("action_name"
) but it's not forced to bind actual actions to it, as theme's developers might just did it to make theme more extensible, and in fact never use it inside theme.
So you can just bind your own code via add_action("colormag_before", "your_function_name"
) in a child theme or plugin, and it will work.
And obviously if you want just to check if hook is used already somewhere in theme, just search through theme's code for add_action("colormag_before"
(or add_action( "colormag_before"
or add_action('colormag_before'
or add_action( 'colormag_before'
. these are just variation with different kinds of how it can be spelled)
If you can search via regular expression it will be add_action\(\s*['"]colormag_before
I've found the solution.
In my plugin's code, for modifying the content I was only using the is_page( $page_id )
condition to check if is the page I wanted to modify. Adding the in_the_loop()
condition solved the problem.
Anyway, thanks Mikhail for the contribution.