Clicky

  1. Home
  2. Developer Docs
  3. General
  4. How to modify AMP plugin and make it update proof

How to modify AMP plugin and make it update proof

In this blog post, I will cover how to modify AMP plugin (AMPforWP plugin) and preserve those changes and make it update proof. We will create a custom plugin and extend the functionality of AMPforWP.

Our Goal: Create an Extension

In this example, we will cover how to add Custom banner at the end of the post content.

Create an extension

Let’s start writing our plugin

First, create a file in your plugin folder called amp-custom-banner-extension.php and write the plugin header. Or paste this below code in the file you just created.

Let’s go to our plugin page and see what we have got.

Plugins

Now AMP Custom Banner Extension plugin is ready, let’s add the code that will add the banner after the post content.

I’ll go through the code once and explain to you what it does.

exit if accessed

Image Markup

We are hooking the markup function amp_custom_banner_extension_insert_banner to ampforwp_after_post_content, this hook is created in AMPforWP plugin and we are attaching banner markup code to the hook.

If you are wondering what Hooks are? Then check out this very good article by TreeHouse.

Our plugin is ready, let’s activate it and see how it looks.

Now we can see the banner below the post, Yay!!!

Banner is looking great, but it is aligned left, its time to add some styling and make the banner look prettier.

Styling the banner

This will insert the styling code to align the banner in the center.

Let us check how the banner is looking now.

Layout responsive

Looks much better now. The last thing remaining is to make the banner responsive and it will look good on all type of devices. So we need to add layout="responsive" in image markup.

Here is the final code also I’m adding it in the GitHub ( https://github.com/MohammedKaludi/amp-custom-banner-extension/ ), do feel free to contribute it.

Over to you.

Please do let me know your thoughts and was this tutorial helpful? Also, I’m going create more tutorials like these so your feedback will help me improve the articles.

Ask your Questions Directly!
If you can't find the solutions in this article, then just ask us in the comments and we will answer it for you!
Updated on April 27, 2020

    Are you still looking for a solution?

    Then fill out the below form and we will reach out to you within a few hours.

    Was this article helpful?

    Related Articles

    Comments

    1. I need to put two banners in different places, but It’s give me an error when I try to duplicate the action.
      Any thoughts? Thanks.

      1. Hi Felipe,

        Could you please tell us how you are adding it and what error, Will you please elaborate more about your issue so that we will understand and help you.

    Leave a Comment