Hooks in AMP Theme Framework

Let’s dig into one of the most important part of AMP theme framework and i.e., “Hooks”

We have added extra hooks in our AMP Theme Framework which will make the theme more playable.

Here is the complete list of all our hooks including their functionalities:

  1. Sitewide 
  2. single.php
  3. index.php

Sitewide { These hooks will run throughout the AMP website }


Actions Hooks

Description

amp_meta

It is used to add things in the head section of AMP which will come handy if you want to add some extra meta tags, to add extra js of AMP components and other things that will go in the head section.


amp_css

It is connected inside <style amp-custom> with the help of which you can add your own styling in AMP pages


amp_start

This hook is connected immediately after the beginning of the body tag. There are many use cases of it and some of them are GTM and analytics.


amp_end

You can use this one to add things before the end of the body tag, the most common usage is to add analytics. You can even add the social sticky with this hook.


 amp_after_header

It is useful if you want to add things right after the end of your header, like if you want to add view-non-amp or an ad immediately after the header then you can use this hook


amp_before_footer

It will be useful If you want to add things right after the article but before the footer.


amp_sidebar_start

This hook is connected right after the beginning of the amp-sidebar. If you want to add more things inside the sidebar and at the beginning of the sidebar, you can use this hook safely.


amp_sidebar_end

It’s the same as the above one but will be useful to add things before the end of the sidebar.


amp_post_template_head

It is used to add extra things in Head section of AMP which will come in handy if you want to add extra meta, JS of AMP components, etc..,


amp_post_template_css

It is used to add extra CSS to your AMP pages

single.php { Posts and Pages }


Actions Hooks

Description

ampforwp_before_post_content

This hook executes before the loop (single posts/pages). It can be used to add anything just above the loop.


ampforwp_after_post_content

This hook executes after the content.

index.php { These hooks will execute on HomePage}


Actions Hooks

Description

amp_before_loop

If you want to add few components or things or text above the loop of index, archive, and search then you can use this hook with ease


amp_after_loop

Do the same thing as the previous one, but is used to add components and any AMP related things after the end of the loop

We are going to add more hooks including components specific hooks in our future updates if you want you can also contribute to it.

That’s it for this tutorial!

We hope it helped you. If you have any feedback or questions, then please share them in the comments section below.

Share
Published by
Marqas

How to create an AWeber form in AMP

If you want to add an AWeber form in AMP then first you need to…

3 years ago

How to setup webpushr notification in AMP

Webpushr is the fastest growing web push notifications platform that marketers love & developers rely…

3 years ago

How to add Adobe Analytics in AMP

Follow these steps to add Adobe Analytics in AMP Step 1: Go to WordPress Admin Area -> AMP…

3 years ago

What is the CWV plugin all about

Core Web Vitals are the subset of Web Vitals that apply to all web pages,…

4 years ago

How to fix “Alternate page with proper canonical tag” Page Index issue in Google Search Console

The following reasons can be shown for non-indexing. Server error (5xx) Your server returned a 500-level…

4 years ago

Google Analytics ( GA4 ) integration in AMPforWP

We have added the Google Analytics 4 ( GA 4 ) integration in AMPforWP v1.0.80.…

4 years ago