How to Add an Action & Filter Hook in WordPress Website?

Table of Contents

Hooks are an essential part of WordPress development as they provide a way to modify the functionality of a theme or plugin without editing the original code. It allows users to add custom code or content to a specific location within WordPress, such as adding a social sharing button to a blog post or displaying custom content in the header section.

Requirement  – This is a feature of Nexter Extension (Free) plugin, make sure its installed & activated to enjoy all its powers.

You need to know custom coding to utilize the power of hooks, but the Nexter Theme Builder has many predefined hooks that you can use to add content to various locations of your website. This feature makes it possible for you to add custom code or content without the need for extensive coding knowledge.

To add content through hooks using the Nexter Theme Builder, follow the steps –

1. From the Dashboard, go to Nexter Settings > Theme Builder > Add New Template.

2. In the popup, select Hooks from the Select Template dropdown.

3. Then, in the Name of Template field, add the template name.

4. After that, you can click on the Additional Settings link.

From the Actions Hooks dropdown, you have to select the hook.

  • Html Before – This will place the content right at the top of the HTML page. It will be placed before the <html> code begins.
  • Head Top – This will place the content right after the <head> tag. It is ideal for adding some meta tags.
  • Head Bottom – This will place the content right before the </head> tag on the HTML page. This can be used to add some additional CSS or js on the site.
  • Wp Head – This will place the content before the <title> tag.
  • Body Top – This will place the content after the <body> tag starts. 
  • Header Before – This will place the content before the page header i.e. before <header> tag. This can be useful to show some messages like sales or discount offers before the page header.
  • Header After – This will place the content after the page header i.e. after </header> tag. Using this, you can show some content in between the header and body content.
  • Content Top – This will place the content right after the page container starts.
  • Content Bottom – This will place the content right before the page container ends.
  • Comments Before – This will place the content before the page or post comments start.
  • Comments After – This will place the content after the page or post comment form ends.
  • Sidebar Before – This will place the content at the start of the sidebar.
  • Sidebar After – This will place the content at the bottom of the sidebar.
  • Footer Before – This will place the content before the footer starts.
  • Footer After – This will place the content after the footer ends.
  • Body Bottom – This will place the content right before the </body> tag.
  • Wp Footer – This will place the content between </footer> and </body> tags.

5. Then you need to set the priority of the specific hook from the Priority field.

Lower the number earlier will be the execution of the hook.

6. Once done, click on the Next button.

7. On the next screen, you have to set the appropriate display conditions.

From the Include In dropdown, you have to select where the template will be visible.

Then, from the Exclude From dropdown, you can set where the template won’t show.

In both sections, you will find the same location options that are available in the header template.

8. Once done, then click on the Create button. 

9. Then it will open the WordPress editor, where you can use the WordPress blocks or Elementor to create the actual layout and content of the template.

10. Once done, publish the template.

Now your template will be created and will show as per the set display conditions.

Also, read How to add Code Snippets for FREE in WordPress.

Still in Doubt? Let’s Assist You

Need Help? Ask AI Bot

Have Feedback or Questions?

Join our WordPress Community on Facebook!

Related Docs