Available hooks in ampforwp WordPress plugin

In this tutorial, I am going to share the list of available hooks in ampforwp WordPress plugin If you want to modify your AMP pages, this hooks will helps you without modifying the original plugin files.

Available hooks in ampforwp WordPress plugin

The list of hooks functionality:

Sitewide { These hooks will run throughout the AMP website }

Actions HooksDescription
amp_post_template_headIt is used to add extra things in Head section of AMP which will come in handy if you want to add extra metas, JS of AMP components, etc..,
amp_post_template_cssIt is used to add extra CSS to your AMP pages
ampforwp_body_beginningIt is executed right after the beginning of Body tag which can be very useful to add things like Analytics.
ampforwp_after_headerIt is executed right after the header section of AMP
below_the_header_design_1 [ Design-1 only ]It is executed right after the header section of AMP
amp_post_template_above_footerIt executes right before the footer.php
amp_post_template_footerIt executes after the footer and just before the end of body tag.
pre_amp_render_postThis hook will only work in AMP environment.
amp_experiment_meta
amp_meta
ampforwp_after_amp_menu
amp_before_footer
amp_footer_link
amp_sidebar_start
amp_sidebar_end

single.php { Posts and Pages }

Actions HooksDescription
ampforwp_post_before_design_elementsThis hook runs before the elements like breadcrumb, title, content meta-info etc which are present in elements folder of each design.
ampforwp_post_after_design_elementsThis hook runs after the elements like breadcrumb, title, content meta-info etc which are present in elements folder of each design.
ampforwp_single_design_type_handle_d1This hook executes after the Next-Previous Links.
ampforwp_below_author_box
ampforwp_push_notification_widget

Note: In Swift pages are served through page.php

archive.php { These hooks will execute on Archive Pages }

Actions HooksDescription
ampforwp_post_before_loopThis hook executes before the loop (Home and Archive). It can be used to add anything just above the loop.
amp_before_loop [ Swift ]This hook executes before the loop (Home and Archive). It can be used to add anything just above the loop.
ampforwp_between_loopThis hook executes in between the loop (Home and Archive). It can be used to add anything in between the loop. It has $count variable as a parameter which can be used to count the number of posts which can help greatly to decide where exactly you want to use this hook in the loop.
ampforwp_post_after_loopThis hook executes after the loop (Home and Archive). It can be used to add anything just below the loop.
amp_after_loop [ Swift ]This hook executes after the loop (Home and Archive). It can be used to add anything just below the loop.
ampforwp_loop_before_pagination
Actions HooksDescription
ampforwp_global_after_footerThis hook executes at the end of the footer i.e., footer.php

frontpage.php { These hooks will run on Custom FrontPage of Design 1,2 and 3 only }

Actions HooksDescription
ampforwp_frontpage_above_loopThis hook executes before the content of Frontpage.
ampforwp_frontpage_below_loopThis hook executes after the content of Frontpage.

header-bar.php { These hooks runs in the “<header>” section }

Actions HooksDescription
ampforwp_header_top_design{designno}This hook executes at the beginning of Header
ampforwp_header_search [ Design 1,2,3 ]It executes with the search button present in the header. You can use it to add your own search button as well.
ampforwp_call_button [ Design 1,2,3 ]It executes with the call button present in the header. You can use it to add your own call button as well.
ampforwp_header_bottom_design{designno}This hook executes at the end of the Header.

index.php { These hooks will execute on HomePage }

Actions HooksDescription
ampforwp_home_above_loopThis hook is used to add the things above the Homepage loop.
amp_before_loop [ Swift ]This hook executes before the loop (Home and Archive). It can be used to add anything just above the loop.
ampforwp_post_before_loopThis hook executes before the loop (Home and Archive). It can be used to add anything just above the loop.
ampforwp_between_loopThis hook executes in between the loop (Home and Archive). It can be used to add anything in between the loop. It has $count variable as a parameter which can be used to count the number of posts which can help greatly to decide where exactly you want to use this hook in the loop.
ampforwp_post_after_loopThis hook executes after the loop (Home and Archive). It can be used to add anything just below the loop.
amp_after_loop [ Swift ]This hook executes after the loop (Home and Archive). It can be used to add anything just below the loop.
ampforwp_home_below_loopThis hook is used to add the things above the Homepage loop.
ampforwp_area_above_loop [ Design 3

search.php { These hooks will run on Search Pages }

Actions HooksDescription
ampforwp_post_before_loopThis hook executes before the loop (Home and Archive). It can be used to add anything just above the loop.
amp_before_loop [ Swift ]This hook executes before the loop (Home and Archive). It can be used to add anything just above the loop.
ampforwp_between_loopThis hook executes in between the loop (Home and Archive). It can be used to add anything in between the loop. It has $count variable as a parameter which can be used to count the number of posts which can help greatly to decide where exactly you want to use this hook in the loop.
ampforwp_post_after_loop This hook executes after the loop (Home and Archive). It can be used to add anything just below the loop.
amp_after_loop [ Swift ]This hook executes after the loop (Home and Archive). It can be used to add anything just below the loop.

Elements

comments.php { Comments in Single }

Actions HooksDescription
ampforwp_before_comment_hookThis hook executes right before the Comments.
ampforwp_reply_comment_form
This hook executes right after the content of each comment.
ampforwp_after_comment_hookThis hook executes right after the Comments.

content.php { Content of Post }

Actions HooksDescription
ampforwp_inside_post_content_before [Design-1]This hook executes before the content. It works in Design-1 only.
ampforwp_before_content_hook
ampforwp_before_post_contentThis hook executes before the content.
ampforwp_after_post_content
This hook executes after the content.

featured-image.php { Featured Image of Post }

Actions HooksDescription
ampforwp_before_featured_image_hookIt executes right before the featured image in Single and Custom FrontPage.
ampforwp_after_featured_image_hookIt executes right after the featured image in Single and Custom FrontPage.

meta-info.php [ Author, categories list etc ]

Actions HooksDescription
ampforwp_before_meta_info_hook [ Design 1,2,3 ]
ampforwp_after_meta_info_hook [ Design 1,2,3 ]

meta-taxonomy.php [ Author box, Tags etc ]

Actions HooksDescription
ampforwp_before_meta_taxonomy_hook [ Design 1,2,3 ]
It executes right before the Meta taxonomy in Single.
ampforwp_after_meta_taxonomy_hook [ Design 1,2,3 ]It executes right after the Meta taxonomy in Single.
Actions HooksDescription
ampforwp_above_related_postThis hook executes right above the Related Posts in Single.
ampforwp_between_related_postThis hook executes between the Related Posts in Single. It can be used to add things like Ads in between the related posts of single.
ampforwp_below_related_post
This hook executes right below the Related Posts in Single.

social-icons.php { Social Icons in Single }

Actions HooksDescription
ampforwp_before_social_icons_hook
It runs before the Social icons in Single.
ampforwp_after_social_icons_hookIt runs after the Social icons in Single.

title.php { Title of Single Post }

Actions HooksDescription
ampforwp_above_the_titleThis hook runs before the Title in Single.
ampforwp_below_the_titleThis hook runs after the Title in Single.

AMP Panel settings { These hooks will run throughout the AMP option Panel  }

Actions HooksDescription
ampforwp_remove_unused_optionsIf you want to remove unused sections from AMP options panel then use this hook.
ampforwp_options_enablerBy using this hook you can enable the required options in the AMP Options Panel when AMP Theme Framework is activated.
ampforwp_options_removerBy using this hook you can remove the required options in the AMP Options Panel when AMP Theme Framework is activated.
amp_template_mode_hide_opt_arrayBy using this hook you can hide option in Template- mode
amp_template_mode_show_opt_array
By using this hook you can show option in Template- mode

Reference: https://ampforwp.com/tutorials/article/hooks-in-ampforwp/

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:


Prem Tiwari

An engineer by profession and a passionate blogger by heart. Founder of FreeWebMentor.com (A Programming blog for beginners), Tech Speaker at various forums. A part from this he is an open source enthusiast, WordPress Lover, Blogger, SEO, and Growth Strategic.