-
Notifications
You must be signed in to change notification settings - Fork 32
Available Functions for Ver. 2 and below
- dfi_get_image_id( $image_url )
- dfi_get_image_thumb( $image_url, $size = "thumbnail" )
- dfi_get_image_url( $attachment_id, $size = "full" )
- dfi_get_post_attachment_ids( $post_id )
- dfi_is_attached( $attachment_id, $post_id )
- dfi_get_image_title( $image_url )
- dfi_get_image_title_by_id( $attachment_id )
- dfi_get_image_alt( $image_url )
- dfi_get_image_alt_by_id( $attachment_id )
- dfi_get_image_caption( $image_url )
- dfi_get_image_caption_by_id( $attachment_id )
Gets the attachment id of the image by its URL
.
Params
- $image_url (String) - The
URL
of the full size image whose attachment_id is required.
This function returns
attachment_id
on success andnull
on failure.
Usage
$attachment_id = dfi_get_image_id( "http://example.com/wp/wp-content/uploads/2013/10/image.jpg" );
//returns attachment id for this image
Fetches the image thumbnail url of specific size.
Params
- $image_url (String) - The
URL
of the full size image. - $size(String) - The required size of the image. The available values are
thumbnail
(Default),medium
,large
andfull
.
This function returns
Image URL
on success andnull
on failure.
Usage
$thumbnail = dfi_get_image_thumb( "http://example.com/wp/wp-content/uploads/2013/10/image.jpg", "thumbnail" );
//output: http://example.com/wp/wp-content/uploads/2013/10/image-150x150.jpg
Fetches the image thumbnail url of specific size by attachment id.
Params
- $attachment_id (Integer) - The
attachment id
of the image. - $size(String) - The required size of the image. The available values are
thumbnail
(Default),medium
,large
andfull
.
This function returns
Image URL
on success andnull
on failure.
Usage
$thumbnail = dfi_get_image_thumb( 57, "thumbnail" );
//output: http://example.com/wp/wp-content/uploads/2013/10/image-150x150.jpg
Fetches all attachment ids of the image attached to this particular post.
Params
- $post_id (Integer) - The id of the post to retrieve data from.
This function returns
array
of ids on success andempty array
on failure.
Usage
$attachment_ids= dfi_get_post_attachment_ids( 57 );
//output: array(0 => "5", 1 => "7")
//You can get the attachment ids inside the post loop by using something like this
$attachment_ids= dfi_get_post_attachment_ids( the_ID() );
Checks if the image is attached with the particular post.
Params
- $attachment_id (Integer) - The
attachment id
of the image. - $post_id (Integer) - The id of the post to check.
This function returns
true
(boolean) if the image is attached with the post otherwisefalse
.
Usage
dfi_is_attached( 57, 7 );
//output: true
When you add an image to media library, you'll have the option to enter a title, alt text and a caption.
Title is primarily for back end use, this holds the name of your image. Giving each image a human-readable title may pay dividends when your Media Library is much larger.
Alt text is descriptive text that appears when you hold your mouse over an image in a web page (or when the image does not appear). Alt text is important for web site visitors with visual or audio impairments who might use special readers to explore your site, and may also be used by search engines indexing your site.
The caption can be displayed below the image in the viewer that appears when a visitor clicks on your gallery image to zoom.
DFI provides following set of functions for interaction with these fields.
Fetches the title for particular image.
Params
- $image_url (String) - The
URL
of the full size image whose attachment_id is required.
This function returns
image title
(String) on success andnull
on failure.
Usage
$title = dfi_get_image_title( "http://example.com/wp/wp-content/uploads/2013/10/image.jpg" );
//Output: The image title
Fetches the title for particular image by attachment id.
Params
- $attachment_id (Integer) - The
attachment id
of the image.
This function returns
image title
(String) on success andnull
on failure.
Usage
$title = dfi_get_image_title_by_id( 57 );
//Output: The image title
Fetches the alternate text for particular image.
Params
- $image_url (String) - The
URL
of the full size image whose attachment_id is required.
This function returns
alternate text/alt
(String) on success andnull
on failure.
Usage
$alt = dfi_get_image_alt( "http://example.com/wp/wp-content/uploads/2013/10/image.jpg" );
//Output: The image alternate text
Fetches the alternate text for particular image by attachment id.
Params
- $attachment_id (Integer) - The
attachment id
of the image.
This function returns
image aternate text
(String) on success andnull
on failure.
Usage
$alt = dfi_get_image_alt_by_id( 57 );
//Output: The image alternate text
Fetches the caption for particular image.
Params
- $image_url (String) - The
URL
of the full size image whose attachment_id is required.
This function returns
image caption
(String) on success andnull
on failure.
Usage
$caption = dfi_get_image_caption( "http://example.com/wp/wp-content/uploads/2013/10/image.jpg" );
//Output: The image caption
Fetches the caption for particular image by attachment id.
Params
- $attachment_id (Integer) - The
attachment id
of the image.
This function returns
image caption
(String) on success andnull
on failure.
Usage
$caption = dfi_get_image_caption_by_id( 57 );
//Output: The image caption