Rendering - Function
SleekPixel provides several PHP functions that allow you to easily render and manipulate dynamic images in your WordPress theme or plugin. These functions offer flexibility in how you integrate SleekPixel-generated images into your site.
get_image_url
This function retrieves the URL of a SleekPixel-generated image.
Parameters
The function accepts an array with the following keys:
id
(required): The ID of the SleekPixel image.key
(required): The key or an array of keys for the image. This key is used to uniquely identify the image in the cache.postId
(optional): The ID of the post associated with the image.data
(optional): Custom data to merge with the image data. This data is merged recursively with other data.
Usage
$imageUrl = sleekPixel_get_image_url([ 'id' => 123, 'key' => 'my_image_key', 'postId' => get_the_ID(), 'data' => [ "post" => [ "title" => "Custom Title" ] ] ]); echo $imageUrl;
Copy
Note: The data
parameter is recursively merged with other image data, allowing you to override or add specific values without affecting the entire data structure.
get_image
This function returns an HTML <img>
tag for a SleekPixel-generated image.
Parameters
The function accepts the same parameters as get_image_url
.
Usage
$imageHtml = sleekPixel_get_image([ 'id' => 123, 'key' => 'my_image_key', 'postId' => get_the_ID(), 'data' => [ "post" => [ "title" => "Custom Title for Image" ] ] ]); echo $imageHtml;
Copy
render_image
This function directly outputs an HTML <img>
tag for a SleekPixel-generated image.
Parameters
The function accepts the same parameters as get_image_url
.
Usage
sleekPixel_render_image([ 'id' => 123, 'key' => 'my_image_key', 'postId' => get_the_ID(), 'data' => [ "post" => [ "title" => "Another Custom Title" ] ] ]);
Copy
These functions provide a convenient way to integrate SleekPixel-generated images into your WordPress theme or plugin. Choose the function that best suits your needs based on whether you need the image URL, HTML, or direct output. Remember that the key
parameter is crucial for uniquely identifying and caching the generated image, and the data
parameter allows for flexible customization of the image content.