-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API call in amp pages when page load #89
Comments
I think I am looking for something similar. I would like to connect this "sample" to my wordpress api and useless WP just as headless Backend and this "sample" as front. Any suggestion how to do it? |
Yes, I am looking for the same. Rest API call in AMP page. |
Do you mean requesting data from the WordPress REST API? If using the official AMP plugin for WordPress, the necessary CORS headers are added automatically. The headers are added automatically by So you just use the add_shortcode(
'amp_latest_posts',
function() {
$endpoint = rest_url( 'wp/v2/posts' );
/*
* Enqueue scripts for when shortcode is used on non-AMP pages. These are unnecessary on AMP pages because the
* post-processor will automatically add them when it encounters <amp-list>.
*/
wp_enqueue_script( 'amp-list' );
wp_enqueue_script( 'amp-mustache' );
ob_start();
?>
<amp-list src="<?php echo esc_url( $endpoint ); ?>" items="." layout="fixed-height" height="300" width="auto">
<template type="amp-mustache">
<div>
<a href="{{link}}">{{title.rendered}}</a>
</div>
</template>
</amp-list>
<?php
return ob_get_clean();
}
); |
How can i make an api call in my amp page. api response is in json format
The text was updated successfully, but these errors were encountered: