I'm creating a child theme based on Jupiter and need to append some HTML to the end of a div generated by Jupiter's theme files. Problem is, this div is generated in multiple theme files, and I don't want to copy-paste my HTML into multiple theme files.

In a nutshell:

<div class="mk-header-holder"><!-- this is the div generated by Jupiter, but across multiple theme files-->

   <!-- Some HTML generated by Jupiter -->

   <div class="my-custom-code"><!-- I want to add this with PHP if possible, regardless of which theme file is loaded-->

Is this possible with PHP using WordPress, or will I have to rely on jQuery?

  • 1
    I would either contact the theme author or see whether there are any hooks within the theme that you could use. Perhaps instead of editing a bunch of theme files, there's an action or filter that is always run in that area, to where you could add the div into the actual HTML/PHP. – WebElaine Nov 20 '17 at 21:19
  • If there weren't a hook, is it still possible to do this with PHP/WordPress core features, or do you think I'd need to rely on JavaScript? – user3183717 Nov 20 '17 at 21:34
  • It just depends on how the theme is coded. Looks like a premium theme so there's no way to tell as an outsider. If there's no hook, perhaps there's a sidebar or a template part, something that's called from all of the various locations. Look for code that's identical across all the different files. – WebElaine Nov 20 '17 at 21:47
  • You'll also want to make sure to create a child theme regardless of which approach you take. That way when updates are released, your changes won't be lost. – WebElaine Nov 20 '17 at 21:47
  • It's possible using output buffers. Basically, you capture all the output, then change it. – janh Nov 20 '17 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.