Resource Information
Method | GET |
---|---|
URL | https://public-api.wordpress.com/rest/v1.1/sites/$site/shortcodes/render |
Requires authentication? | Yes |
Method Parameters
Parameter | Type | Description |
---|---|---|
$site | (int|string) | Site ID or domain |
Query Parameters
Parameter | Type | Description |
---|---|---|
context | (string) |
|
http_envelope | (bool) |
|
pretty | (bool) |
|
meta | (string) | Optional. Loads data from the endpoints found in the 'meta' part of the response. Comma-separated list. Example: meta=site,likes |
fields | (string) | Optional. Returns specified fields only. Comma-separated list. Example: fields=ID,title |
callback | (string) | An optional JSONP callback function. |
shortcode | (string) | The query-string encoded shortcode string to render. Required. Only accepts one at a time. |
Response Parameters
Parameter | Type | Description |
---|---|---|
shortcode | (string) | The shortcode that was passed in for rendering. |
result | (html) | The rendered HTML result of the shortcode. |
scripts | (array) |
An array of JavaScript files needed to render the shortcode. Returned in the format of { "script-slug" : { "src": "http://example.com/file.js", "extra" : "" } } where extra contains any neccessary extra JS for initializing the source file and src contains the script to load. Omitted if no scripts are neccessary. |
styles | (array) |
An array of CSS files needed to render the shortcode. Returned in the format of { "style-slug" : { "src": "http://example.com/file.css", "media" : "all" } } . Omitted if no styles are neccessary. |
Resource Errors
These are the possible errors returned by this endpoint.
HTTP Code | Error Identifier | Error Message |
---|---|---|
403 | unauthorized | User cannot access this private blog. |
403 | unauthorized | User cannot access this restricted blog |
400 | invalid_shortcode | Only one shortcode can be rendered at a time. |
400 | invalid_shortcode | The requested shortcode does not exist. |
400 | invalid_shortcode | The shortcode parameter must begin and end with square brackets. |
403 | unauthorized | Your token must have permission to post on this blog. |
Example
curl \ -H 'authorization: Bearer YOUR_API_TOKEN' \ 'https://public-api.wordpress.com/rest/v1/sites/82974409/shortcodes/render?shortcode=%5Bgallery%20ids%3D%22729%2C732%2C731%2C720%22%5D'
<?php $options = array ( 'http' => array ( 'ignore_errors' => true, 'header' => array ( 0 => 'authorization: Bearer YOUR_API_TOKEN', ), ), ); $context = stream_context_create( $options ); $response = file_get_contents( 'https://public-api.wordpress.com/rest/v1/sites/82974409/shortcodes/render?shortcode=%5Bgallery%20ids%3D%22729%2C732%2C731%2C720%22%5D', false, $context ); $response = json_decode( $response ); ?>
Response
{ "shortcode": "", "result": "", "scripts": { "premium-content-frontend": { "src": "https:\/\/s2.wp.com\/wp-content\/plugins\/full-site-editing-plugin\/486733432\/premium-content\/view.js?ver=c0883a553f92c75552f0225c5127257b" }, "jetpack-carousel": { "src": "\/wp-content\/mu-plugins\/carousel\/jetpack-carousel.js?ver=wpcom", "extra": "var jetpackCarouselStrings = {\"widths\":[370,700,1000,1200,1400,2000],\"is_logged_in\":\"1\",\"lang\":\"en\",\"ajaxurl\":\"https:\\\/\\\/apiexamples.wordpress.com\\\/wp-admin\\\/admin-ajax.php\",\"nonce\":\"f3b509b310\",\"display_exif\":\"1\",\"display_comments\":\"1\",\"display_geo\":\"1\",\"single_image_gallery\":\"1\",\"single_image_gallery_media_file\":\"\",\"background_color\":\"black\",\"comment\":\"Comment\",\"post_comment\":\"Post Comment\",\"write_comment\":\"Write a Comment...\",\"loading_comments\":\"Loading Comments...\",\"download_original\":\"View full size <span class=\\\"photo-size\\\">{0}<span class=\\\"photo-size-times\\\">\\u00d7<\\\/span>{1}<\\\/span>\",\"no_comment_text\":\"Please be sure to submit some text with your comment.\",\"no_comment_email\":\"Please provide an email address to comment.\",\"no_comment_author\":\"Please provide your name to comment.\",\"comment_post_error\":\"Sorry, but there was an error posting your comment. Please try again later.\",\"comment_approved\":\"Your comment was approved.\",\"comment_unapproved\":\"Your comment is in moderation.\",\"camera\":\"Camera\",\"aperture\":\"Aperture\",\"shutter_speed\":\"Shutter Speed\",\"focal_length\":\"Focal Length\",\"copyright\":\"Copyright\",\"comment_registration\":\"0\",\"require_name_email\":\"1\",\"login_url\":\"https:\\\/\\\/apiexamples.wordpress.com\\\/wp-login.php\",\"blog_id\":\"82974409\",\"meta_data\":[\"camera\",\"aperture\",\"shutter_speed\",\"focal_length\",\"copyright\"],\"local_comments_commenting_as\":\"<p id=\\\"jp-carousel-commenting-as\\\">Commenting as apiexamples<\\\/p>\",\"reblog\":\"Reblog\",\"reblogged\":\"Reblogged\",\"reblog_add_thoughts\":\"Add your thoughts here... (optional)\",\"reblogging\":\"Reblogging...\",\"post_reblog\":\"Post Reblog\",\"stats_query_args\":\"blog=5836086&v=wpcom&tz=0&user=1&user_id=78972699&subd=public-api\",\"is_public\":\"1\",\"reblog_enabled\":\"\"};" } }, "styles": { "premium-content-frontend": { "src": "https:\/\/s2.wp.com\/wp-content\/plugins\/full-site-editing-plugin\/486733432\/premium-content\/style.css?m=1610671514h&ver=1610671514", "media": "all" }, "jetpack-carousel": { "src": "https:\/\/s1.wp.com\/wp-content\/mu-plugins\/carousel\/jetpack-carousel.css?m=1592560282h&ver=wpcom", "media": "all" } } }