-1

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!

2 Answers 2

2

There 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

-1

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.

1
  • While you may have solved your problem, this answer has nothing to do with the actual question you asked, so isn’t very useful to other users. If you post an answer, it needs to address the question that was posted. Also, in future please ask about the problem you’re actually trying to solve, not a hypothetical solution. Mar 12, 2020 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.