Title: Insert after/before element with specific class
Last modified: August 28, 2020

---

# Insert after/before element with specific class

 *  Resolved [Pascalvd](https://wordpress.org/support/users/pascalvd/)
 * (@pascalvd)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/insert-after-before-element-with-specific-class/)
 * Hi,
 * I was wondering if it is possible to automatically insert the ToC after/before
   an element with a certain class. I’m familiar with PHP and JavaScript so no issues
   with writing some code. Is this possible via hooks? Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Steven](https://wordpress.org/support/users/shazahm1hotmailcom/)
 * (@shazahm1hotmailcom)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/insert-after-before-element-with-specific-class/#post-13351539)
 * There is not a filter that can be hooked into. Here’s the section of the code
   which does the insert.
    - [https://github.com/shazahm1/Easy-Table-of-Contents/blob/2.0.11/easy-table-of-contents.php#L557-L635](https://github.com/shazahm1/Easy-Table-of-Contents/blob/2.0.11/easy-table-of-contents.php#L557-L635)
 * I’m open to adding a filter if you have a recommendation.
 *  Thread Starter [Pascalvd](https://wordpress.org/support/users/pascalvd/)
 * (@pascalvd)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/insert-after-before-element-with-specific-class/#post-13354316)
 * Hi Steven,
 * Thanks for your reply. The problem is that I’m also dynamically inserting ads
   within the content, which are also being inserted before the first heading (just
   like the ToC). However, I want the ad to appear below the ToC, but instead it
   was being inserted before the ToC.
 * I was thinking of adding a functionality so people can enter a class name and
   indicate if the ToC should be inserted before or after the element with that 
   specific class. In my case that would be the class I have assigned to my ad container.
 * However, this functionality is no longer needed by me, because I figured I could
   achieve what I wanted by adjusting the priority of my ad insertion filter. I’m
   not sure if this feature is something other people would be interested in.
 * Anyway, thanks for the reply once again.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Insert after/before element with specific class’ is closed to new replies.

 * ![](https://ps.w.org/easy-table-of-contents/assets/icon-256x256.png?rev=3045459)
 * [Easy Table of Contents](https://wordpress.org/plugins/easy-table-of-contents/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/easy-table-of-contents/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/easy-table-of-contents/)
 * [Active Topics](https://wordpress.org/support/plugin/easy-table-of-contents/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/easy-table-of-contents/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/easy-table-of-contents/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Pascalvd](https://wordpress.org/support/users/pascalvd/)
 * Last activity: [5 years, 9 months ago](https://wordpress.org/support/topic/insert-after-before-element-with-specific-class/#post-13354316)
 * Status: resolved