Skip to content

Functions

Junaid Bhura edited this page May 24, 2019 · 12 revisions

cloudinary_url( $identifier, $args )

Generates a Cloudinary auto-upload URL for an image. Please read the Best Practices page before using this.

Parameters

  • identifier (integer|string)(required) : Either the ID of the attachment, or a full image URL. If you've entered an image URL, the URL needs to match what you've entered in the Auto Upload Folder field in the settings.
  • args (array)(optional) : Arguments to manipulate the image.

Example Arguments Array

array(
	'transform' => array( // Optional. All transformations go here.
		'width'   => 100,
		'height'  => 100,
		'crop'    => 'fill',
		'gravity' => 'face',
	),
	'file_name' => 'dynamic-file-name', // Optional. If you want to use a dynamic file name for SEO. Don't use the file extension!
);

Allowed Transformations

Here's a list of transformations allowed in this plugin. Click here to see the documentation on the Cloudinary website.

angle
aspect_ratio
background
border
crop
color
dpr
duration
effect
end_offset
flags
height
overlay
opacity
quality
radius
start_offset
named_transformation
underlay
video_codec
width
x
y
zoom
audio_codec
audio_frequency
bit_rate
color_space
default_image
delay
density
fetch_format
gravity
prefix
page
video_sampling
progressive (Supports: true, 'semi', 'steep', 'none')

Example

<?php
$url = cloudinary_url( 123, array(
	'transform' => array(
		'width'   => 300,
		'height'  => 200,
		'crop'    => 'fill',
		'quality' => '80',
		'gravity' => 'face',
	),
	'file_name' => 'dynamic-file-name',
) );
?>

<img src="<?php echo esc_url( $url ); ?>" width="300" height="200" alt="">

If the original URL was:

https://www.yourwebsite.com/wp-content/uploads/2017/12/your-image.jpg

$url will now have the value:

https://res.cloudinary.com/cloud-name/images/w_300,h_200,c_fill,q_80,g_face/auto-mapping-folder/2017/12/your-image/dynamic-file-name.jpg

 


 

cloudinary_update_content_images( $content )

This function is used to update all images entered in the WordPress (TinyMCE) editor in the admin to use Cloudinary URLs on the front-end. You can use this function too if you want to do the same for any custom fields you might have, or whatever you need it for.

Parameters

  • content (string)(required) : The HTML content which contains images.

Return Value

Returns the exact same content, except with the image URLs changed to use Cloudinary.

Note

The content needs to have been entered from the TinyMCE editor in the admin. This is because this function looks for the class wp-image-<id> which is added in the admin. It will not work if it does not find any images which do not have this class.

 


 

cloudinary_get_original_url( $id )

Get the original URL of an image based on it's ID, without modifying it's URL.

Parameters

  • id (integer)(required) : The attachment ID.

 


 

cloudinary_ignore_start()

Use this function if you want Cloudinary to ignore the automatic URL replacement following this line. This is typically followed by a cloudinary_ignore_end() at some point.

 


 

cloudinary_ignore_end()

Use this function if you want Cloudinary to resume the automatic URL replacement. This is typically used after cloudinary_ignore_start().

You can’t perform that action at this time.