Title: Inject code
Last modified: October 7, 2021

---

# Inject code

 *  Resolved [woodypad](https://wordpress.org/support/users/woodypad/)
 * (@woodypad)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/inject-code/)
 * Hello,
    there is a way to use Code Snippets to inject some code in a point of
   the site, perhaps referring to a class or to wordpress hooks. I am using another
   plugin to do this, but I would like to use yours only. I’m trying to do two things,
   1 – insert a before / after element of a block or paragraph or class. 2 – I would
   not like to modify the theme files and I would like to insert the injected modification
   in a given file, without actually modifying it. Is it possible to do it?
 * Thank you

Viewing 1 replies (of 1 total)

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/inject-code/#post-14972713)
 * Hi [@woodypad](https://wordpress.org/support/users/woodypad/),
 * Code Snippets doesn’t really inject code in files, technically speaking. Instead,
   you need to make use of WordPress action and filter hooks to determine where 
   and when your code is executed.
 * If you take a look at the file you want to inject code in and see a call to the`
   do_action` or `apply_filter` function, then you’re in luck – you can use `add_action`
   or `add_filter` to hook in and add code there. If these functions are not used,
   then it gets significantly harder to alter things.
 * You can see a full list of the action and filter [hooks on the WordPress Developer site](https://developer.wordpress.org/plugins/hooks/).
   A lot of themes and plugins also have documentation on this if you don’t want
   to dig into the code.

Viewing 1 replies (of 1 total)

The topic ‘Inject code’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [4 years, 5 months ago](https://wordpress.org/support/topic/inject-code/#post-14972713)
 * Status: resolved