How to Add Header and Footer Code in WordPress AMP Pages


Add Header and Footer Code in WordPress AMP Pages

Add Header and Footer Code in WordPress AMP Pages

How to Add Header and Footer Code in WordPress AMP Pages

In Today AMP (Accelerated Mobile Pages) Series part we going see About insert How to Add Header and Footer Code in WordPress AMP Pages.In our Previous Part, we have seen about How to Add Custom CSS and Google Analytics in WordPress AMP Pages.

In our Previous part, I mention about Header and Footer part in AMP Pages ok now we are going to see about How to insert Header and Footer Code in WordPress AMP Pages.

Just Follow our Below steps to add Header and Footer Code in WordPress AMP Pages.

WP AMP Customization – How to Edit the Footer text in WordPress AMP pages

 

Add Header and Footer Code in WordPress AMP Pages

We can add our Custom functions of WordPress pages add a function like Custom CSS, Google Analytics and Enable the Extra AMP functions like Share Buttons, Embedded support and More.

We can Insert our Custom Code in Header and Footer path by two Methods in WordPress Accelerated Mobile Pages.

  • Add the Function code from our theme’s functions.php file (WP Child Theme safe for Play with Custom Codes)
  • Create Site Specific plugin for add our Custom WP functions

 

AMP pages have two Post Template path one is Header <head> another one is Footer </body>

  • Header Action Hook – amp_post_template_head
  • Footer Action Hook – amp_post_template_footer

Code for Header and Footer

How Add a Header code on WordPress AMP pages?

  • Insert your Custom Code in Your WordPress AMP Pages header part
  • Add this Code in your themes functions.php file or add it in Site Specific WP plugin

 

/*
 * Adding Header and Footer Code in AMP pages in WordPress
 */
 add_action('amp_post_template_header','awts_amp_my_custom_head');
 function awts_amp_my_custom_head($amp_template) {
 ?>
 //Your Custom Codes
 <?php
 }

  • the above code will print your Custom Function’s in Header Part (Above </head>) in WordPress pages

How Add a Footer code on WordPress AMP pages?

  • Same as above one add the Below code in your theme’s functions.php or Site Specific Plugin

 

/*
* Adding Header and Footer Code in AMP pages in WordPress
*/ 
add_action('amp_post_template_footer','awts_amp_my_custom_footer');
function awts_amp_my_custom_footer($amp_template) { 
?>
//Your Custom codes
<?php 
}

  • This code print on Footer part above </body>

 

From editor’s Desk

Currently, AMP does not Support the full third party scripts and features you can add AMP related function on header and footer in WordPress pages.

 


Was this article helpful?
Thanks!

Your feedback helps us improve Allwebtuts.com



13 Shares
+11
Tweet
Share10
Pin1
Stumble1