Rendering - Shortcode
SleekPixel provides a powerful shortcode that allows you to easily embed dynamic images in your WordPress content. This shortcode offers a flexible way to display SleekPixel-generated images within your posts, pages, or custom post types.
Basic Usage
The basic syntax for the SleekPixel shortcode is as follows:
[sleekpixel id="123" key="my_image_key"]
Copy
Parameters
The shortcode accepts several parameters to customize the image output:
id
(required): The ID of the SleekPixel image.key
(required): The key or keys for the image. Multiple keys can be separated by commas.post_id
(optional): The ID of the post associated with the image. If not provided, the current post ID will be used.data
(optional): Custom data to merge with the image data. This should be provided as a JSON-encoded string.
Advanced Usage
Here's an example of a more advanced usage of the shortcode:
[sleekpixel id="123" key="header_image,footer_image" post_id="456" data='{"custom_field": "value"}']
Copy
In this example:
- We're using two keys:
header_image
andfooter_image
. - We're specifying a custom
post_id
of 456. - We're passing custom data as a JSON-encoded string.
Using in Templates
You can also use the shortcode within your PHP templates using the
do_shortcode()
function:
<?php echo do_shortcode('[sleekpixel id="123" key="my_image_key"]'); ?>
Copy
The SleekPixel shortcode provides a convenient way to embed dynamic images in your content without needing to write PHP code. It's particularly useful for content editors who want to include SleekPixel images in their posts or pages.