Skip to content

Instantly share code, notes, and snippets.

@keirwhitaker
Last active August 29, 2015 14:06
Show Gist options
  • Save keirwhitaker/584dbaeb2c87885a98b1 to your computer and use it in GitHub Desktop.
Save keirwhitaker/584dbaeb2c87885a98b1 to your computer and use it in GitHub Desktop.
/**
* Shortcode that outputs a figure in the WordPress content editor generated content
* @author Keir Whitaker ([email protected] | keirwhitaker.com)
*
* @param type $atts The src attribute
* @param type $content The caption for the figcaption
* @return string
*
* Usage [figure src="/wp-content/test.jpg"]This is not linked up but this is <a href="http://yahoo.com">This is the content</a>[/figure]
*
*/
function figure_func( $atts, $content ) {
$a = shortcode_atts( array (
'src' => ''
), $atts );
$content = wp_kses( $content, array (
'strong' => array(),
'a' => array( 'href', 'title' ),
'em' =>array()
) );
$retval .= '<figure>';
$retval .= '<img src="' . $a['src'] . '" />';
$retval .= '<figcaption>' . html_entity_decode( $content ) . '</figcaption>';
$retval .= '</figure>';
return $retval;
}
add_shortcode( 'figure', 'figure_func' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment