-
Notifications
You must be signed in to change notification settings - Fork 381
Adding Custom Shortcodes And Widgets
Ryan Kienstra edited this page Apr 24, 2018
·
7 revisions
Widgets are now supported when adding theme support, and shortcodes are always supported. Here are some considerations for creating custom shortcodes and widgets.
- No inline scripts, as this plugin will strip
<script>
tags on the front-end. Consider using amp-bind instead. - The best practice is to enqueue stylesheets with wp_enqueue_style(). But this plugin will also recognize inline styling, and add it to the
<style amp-custom>
. If the stylesheet causes the total page CSS size to go over the 50 KB limit, it might be stripped. But a new feature in the upcoming1.0
release will reduce the need to strip extra CSS like this. - You can use is_amp_endpoint() to output different markup for AMP and non-AMP pages (doesn't apply to Native AMP). For example, a social sharing widget might output the amp-social-share component on the AMP page:
<?php if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) : ?>
<amp-social-share type="twitter"></amp-social-share>
<?php else : ?>
<a href="https://twitter.com/intent/tweet/?url=http%3A%2F%2Fexample.com">Share</a>
<?php endif; ?>
Notice: Please also see the plugin documentation on amp-wp.org