I would like to write a plugin which injects specific content to every non admin page. This is my first plugin.
I've figured out how can I inject content to every non admin page's head:
<?php
function myfunction() {
?>
<!-- My injected content.... -->
....
<?php
}
if (!is_admin()) {
add_action('wp_head', 'myfunction');
}
Unfortunately I can not figure out how to inject to the body, say an element, because I did not find the appropriate action.
- Injecting a script to head, which injects elements to DOM is not a solution this case, because the injected content must be there at load time, so it may be late to modify the DOM after load.
- The injected content must be "calculated" and the only place it can be calculated is php serverside.
the_content
filter developer.wordpress.org/reference/functions/the_contentwp_footer
instead ofwp_head
, that is inside the body at the bottom of the page. if it is just for a script and you don't care where the content outputs that would be ideal.