Clicky

  1. Home
  2. Extension & Themes
  3. ACF for AMP
  4. How to use Advanced Custom Fields in AMP?

How to use Advanced Custom Fields in AMP?

ACF is a powerful tool and now it can be used on AMP with the help of ACF for AMP. In this article, we will see an overview of the ACF for AMP plugin.

Here are the steps:

  1. Download and Install
  2. Upload and Activate
  3. Done! The ACF for AMP will be visible on the AMP version of your site.

Step 1: After you have downloaded and installed on your WordPress installation, you will see a new section on the left sidebar area.

first step

Overview of the Settings:

1. Title: This is a Title area just for your own reference.

2. Location: Select the location where you want to display the fields. Under the Location section, there are two options.

The first one ‘Show Data on’ allows controlling the pages where the fields will display, such as Posts, Homepage, Archives or displaying it Globally.

The second option ‘Where you want to show the content?‘ helps you to display the data differently the areas within the selected page (the one we selected on the first option).

      • After the Header (Global)
      • Before Featured Image (Single)
      • After Featured Image (Single)
      • After Post Meta (Single)
      • Before Post Meta (Single)
      • Before Post Content (Single)
      • After Post Content (Single)
      • Below the Post (Single)
      • Above the Footer (Sitewide)
      • In the Footer (Sitewide)
      • Shortcode (Manual)

Once you select the shortcode (manual) option shortcode meta box will be displayed from where you can copy the shortcode and paste whereever you want to place in Pages /Post.

3. Conditional Logic Placement: This is an advanced option that allows you to handle the placement anywhere you want. You can target any page, Post type, taxonomy with the help of this. You can also add another logic which makes it more magical. This a very powerful tool to handle the views of the data.

4. PHP Editor: This is where you would enter your field code. Just like you have to enter a small line of PHP code like the_field(‘field_name’); to display field in ACF in the WordPress template. you need to add the same code. You can use any one of the examples mentioned in the ACF documentation.

5. AMP Javascript: This field is only required if you are using some special AMP markup in the PHP code editor that requires an AMP JS. An example would be <amp-carousel> which requires us to load the amp-carousel.js file. If you are displaying the fields normally then it’s not required at all.

Code Examples

Here are some examples of code which you can use in the PHP Editor. Please note that these examples are for demo purpose, if you copy and paste them then it doesn’t Auto-Magically starts to display the fields, you would have to actually use the right field ID.

1. Display a field

2. Retrieving a field as a variable

3. Using conditional statements

4. Working with Array values (checkbox, select, relationship, repeater)

5. Working with the Repeater Field
repeater can be accessed by get_field or the_repeater_field / the_sub_field

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.

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 17, 2019

Was this article helpful?

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help!
Contact Support

Leave a Comment