https://github.com/ampirecity/AMPWPBasics1
Beginner
WordPress and the team behind the AMP plugin for the platform are constantly working to improve things. If you are using one of the official themes you can just stop reading here, with AMP plugin 0.7+ the pages will be converted into AMP automatically.
However, while it could work for personal projects or small businesses, more advances websites might want to use AMP to its fullest. While the high-end project doesn’t require AMP plugin at all, for most cases it is better to start with it onboard. The default settings I use are set to Template Mode: Native with tree shaking and all templates queried checked.
Setting up AMP for WordPress plugin. [CC BY-SA 4.0], via AMPire.city
As for any theme in WordPress, only style.css and index.php are required, but I prefer starting with all of these files:
Enabling fresh AMP WordPress Theme. [CC BY-SA 4.0], via AMPire.city
For tab-junkies like me, I recommend adding a favicon to recognize the tab of the website I am working on, as fast as possible. You can do that by going Appearance > Customize > Site Identity. [CC BY-SA 4.0], via AMPire.city
The whole point of AMP (Accelerated Mobile Pages) is it’s the simplicity and loading speed, therefore avoid installing any unnecessary plugins. One thing is for sure, as AMP plugin will notify you, AMP will work best with caching enabled. There are many cache plugins out there, you can choose the one you prefer. I suggest you do so after developing the theme.
W3 Total Cache example. [CC BY-SA 4.0], via AMPire.city
In order to set up the basic information of your theme, you need to set the header of this file correctly. While not all of these fields are required, this is the basic template for setting up a WordPress theme.
1 2 3 4 5 6 7 8 9 10 11 12 |
/* Theme Name: Self-explanatory. Theme URI: Self-explanatory. Author: Name yourself. Author URI: Advertise yourself. Description: Whatever your heart wants it to be. Version: The version of your release. License: Extra licensing License URI: Self-explanatory Tags: Self-explanatory. Text Domain: required for multi-lingual websites */ |
Setting up style.css correctly. [CC BY-SA 4.0], via AMPire.city
For starters, functions.php can be empty, but in order for style.css to work correctly, you need to load it as a stylesheet file as well. Also, as a personal choice, I add the fonts for the website and enable featured images. At the start of a project my functions.php is as it follows:
1 2 3 4 5 6 7 8 9 10 11 12 |
function enqueue_style() { wp_enqueue_style('style', get_stylesheet_uri()); } add_action('wp_enqueue_scripts', 'enqueue_style'); // Load fonts function load_fonts() { wp_enqueue_style('Exo', 'https://fonts.googleapis.com/css?family=Exo:500,500i,700,700i&subset=latin-ext'); } add_action('wp_enqueue_scripts', 'load_fonts'); // Activate featured images add_theme_support( 'post-thumbnails' ); |
The whole point of header.php and footer.php template files, is to make the general code, above and below the content, the same. You can add the content of these files to any template file in the same way I added to my index.php:
1 2 3 |
That's one small step for man |
1 2 3 4 5 6 7 8 9 10 |
1 2 3 |
Setting up basic template files for the theme results. [CC BY-SA 4.0], via AMPire.city
And that is it, you are now all set up to start developing your own custom AMP WordPress theme.
Originally posted on 3/20/2019
Versions:
WordPress 5.1
AMP 1.02