Hooks - PHP
Below you'll find a list of all available PHP hooks that can be used to extend or adjust the functionality of the plugin.
data
This filter allows modifying the data before it's used to generate the image.
add_filter('sleekPixel/data', function($data, $args) { $imageId = $args['id'] ?? 0; // Modify post title for a specific image if ($imageId === 123) { $data['post']['title'] = 'New Post Title'; } return $data; }, 10, 2);
Copy
data/custom
This filter allows registering custom data which can be chosen inside the editor.
add_filter( "sleekPixel/data/custom", function ($data, $args) { $postId = $args["postId"]; // Add custom data entry 1 $data[] = [ "value" => "customData1", "label" => "Custom data", "data" => get_field('my_field', $postId), ]; // Add custom data entry 2 $data[] = [ "value" => "customData2", "label" => "Custom data 2", "data" => "My custom title #2", ]; return $data; }, 10, 2 );
Copy
image/element/data
This filter allows modifying the data of individual elements within a SleekPixel image.
add_filter('sleekPixel/image/element/data', function($elementData, $image) { // Check if this is the specific image we want to modify if ($image['id'] === 123) { // Loop through the styles of each element foreach ($elementData['styles'] as &$style) { // Check if the element has a 'color' key if (isset($style['color'])) { // Set the color to a primary color $style['color'] = '#007bff'; // Example primary blue color } } } return $elementData; }, 10, 2);
Copy