Skip to content

Instantly share code, notes, and snippets.

@saqibameen
Last active November 14, 2017 12:16
Show Gist options
  • Save saqibameen/458bc993ef1bc4f5ebb104387702faef to your computer and use it in GitHub Desktop.
Save saqibameen/458bc993ef1bc4f5ebb104387702faef to your computer and use it in GitHub Desktop.
WP: Plugin function to return image in specified size (if any), default otherwise.
<?php
/**
* Get Logo.
*
* Returns logo of WPCouple.com in specified width (if any).
*
* @param array $atts Array of attributes.
* @return mixed
*/
function wpc_get_logo( $atts ) {
// Get argument values.
$arguments = shortcode_atts( array( 'size' => null ), $atts );
// Size is set.
if ( ! empty( $arguments['size'] ) ) {
// Set source & size of image in img tag.
$logo = '<img width="' . $arguments['size'] . 'px" src="' . plugins_url( 'images/wp-couple-logo.png', __FILE__ ) . '">';
} else { // Size is not set.
// Set source of image tag.
$logo = '<img src="' . plugins_url( 'images/wp-couple-logo.png', __FILE__ ) . '">';
}
// Return logo.
return $logo;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment