GET /sites/$site/shortcodes/render

Get a rendered shortcode for a site. Note: The current user must have publishing access.

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)
display:
(default) Formats the output as HTML for display. Shortcodes are parsed, paragraph tags are added, etc..
edit:
Formats the output for editing. Shortcodes are left unparsed, significant whitespace is kept, etc..
http_envelope (bool)
false:
(default)
true:
Some environments (like in-browser JavaScript or Flash) block or divert responses with a non-200 HTTP status code. Setting this parameter will force the HTTP status code to always be 200. The JSON response is wrapped in an "envelope" containing the "real" HTTP status code and headers.
pretty (bool)
false:
(default)
true:
Output pretty JSON
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": {
        "spin": {
            "src": "https:\/\/s2.wp.com\/wp-includes\/js\/spin.js?ver=1.3"
        },
        "jquery.spin": {
            "src": "https:\/\/s2.wp.com\/wp-includes\/js\/jquery\/jquery.spin.js?ver=1.3"
        },
        "jetpack-carousel": {
            "src": "https:\/\/s1.wp.com\/wp-content\/mu-plugins\/carousel\/jetpack-carousel.js?ver=20160330",
            "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\":\"687632af4b\",\"display_exif\":\"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\",\"comment_registration\":\"0\",\"require_name_email\":\"1\",\"login_url\":\"https:\\\/\\\/apiexamples.wordpress.com\\\/wp-login.php\",\"blog_id\":\"82974409\",\"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": {
        "jetpack-carousel": {
            "src": "https:\/\/s1.wp.com\/wp-content\/mu-plugins\/carousel\/jetpack-carousel.css?m=1481571546h&ver=20120629",
            "media": "all"
        },
        "jetpack-carousel-ie8fix": {
            "src": "https:\/\/s1.wp.com\/wp-content\/mu-plugins\/carousel\/jetpack-carousel-ie8fix.css?m=1412618825h&ver=20121024",
            "media": "all"
        }
    }
}