0

I write a small cookie consent plugin for a Multisite network installation. So, when the plugin will be finished, it will be available to all instances of a multisite installation.

To make it work, I need to inject a div with a certain ID into every DOM, no matter what theme is installed in that instance. I know, that I could do an "add_action" to inject it to the content or the wp_footer. But since the content sometimes is empty, and the wp_footer isn't defined in every theme, I need some other way to inject my div.

Is there any possiblity to do it, no matter what theme is installed? Are there any hooks available, that every theme uses? Thank you very much in advance, I am pretty new to Wordpress.

3
  • “the wp_footer isn't defined in every theme” It should be. Dec 11 '21 at 12:49
  • Yes, I know. But since this is a network of around 300 instances, there are quiet some themes that don't follow the rules. I just wanted to find a way to spare me the work of looking through all themes and child themes and adapt the faulty ones...
    – what ever
    Dec 11 '21 at 13:35
  • Are you sure any of these themes are missing wp_footer? It’s a requirement and many things won’t work without it. Unless they’re extremely old I’d be very surprised if it was missing. Dec 11 '21 at 16:40
0

You could wait until every other PHP code is done and register a shutdown function like this:

add_action( 'template_redirect', function() {
    register_shutdown_function( 'your_function' );
});

Waiting for template_redirect makes sure you are on a theme page. Be aware that this will add code after the closing </html> tag, so you create invalid HTML.

This is just a dirty workaround. The recommended way is to establish some decent QA (quality assurance) and to make sure that no trash themes without wp_footer() are installed.

1
  • Thank you very much! I guess I'm doomed to inspect all those themes and put the wp_footer(); in them if missing. Sorry for not being able to leave an upvote due to missing reputation :)
    – what ever
    Dec 11 '21 at 14:52

Your Answer

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

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