Below, you’ll find a detailed guide on how to add the AMP Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the AMP Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the AMP Plugin and the shortcodes it provides:
"AMP is a powerful WordPress plugin that accelerates your website's performance on mobile devices. It optimizes your content, ensuring faster load times, enhanced SEO, and improved user experience."
- [amp_playlist]
AMP [amp_playlist] Shortcode
The AMP Plugin shortcode is a versatile tool that pulls data based on the attributes passed. It checks the ‘type’ of data and returns either an audio or video playlist. This code uses the ‘shortcode’ function to determine if the ‘type’ attribute is ‘audio’ or ‘video’. If ‘audio’, it returns an audio playlist; if ‘video’, it returns a video playlist.
Shortcode: [amp_shortcode]
Parameters
Here is a list of all possible amp_shortcode shortcode parameters and attributes:
type
– defines the media type to be either ‘audio’ or ‘video’data
– contains specific settings related to the media
Examples and Usage
Basic example – A simple usage of the shortcode to display an audio playlist.
[amp_playlist type="audio" id="123" /]
Advanced examples
Use the shortcode to display a video playlist by referencing the type and ID. The playlist will load based on the provided ID.
[amp_playlist type="video" id="456" /]
Another advanced usage of the shortcode can be to display a specific audio playlist with additional parameters such as autoplay and loop. If these attributes are set to true, the audio will start playing automatically once the page loads and will loop once it ends.
[amp_playlist type="audio" id="789" autoplay="true" loop="true" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [amp_shortcode]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( self::SHORTCODE, [ $this, 'shortcode' ] );
Shortcode PHP function:
function shortcode( $attr ) {
$data = $this->get_data( $attr );
if ( isset( $data['type'] ) && ( 'audio' === $data['type'] ) ) {
return $this->audio_playlist( $data );
}
if ( isset( $data['type'] ) && ( 'video' === $data['type'] ) ) {
return $this->video_playlist( $data );
}
return '';
}
Code file location:
amp/amp/includes/embeds/class-amp-playlist-embed-handler.php
Conclusion
Now that you’ve learned how to embed the AMP Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply