Files
trestle/includes/shortcodes/shortcodes.php
T

138 lines
3.1 KiB
PHP
Raw Normal View History

<?php
/**
* Trestle shortcodes.
*
* @since 1.0.0
*
* @package Trestle
*/
/*===========================================
* Shortcodes
===========================================*/
add_filter( 'the_content', 'trestle_shortcode_empty_paragraph_fix' );
2015-01-07 10:23:25 -08:00
/**
* Fix for empty <p> tags around shortcodes.
2015-01-07 10:23:25 -08:00
*
* @since 1.0.0
*
* @param string $content HTML content.
*
* @return string Updated content.
*/
function trestle_shortcode_empty_paragraph_fix( $content ) {
$array = array (
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
2014-11-25 13:47:18 -08:00
);
$content = strtr( $content, $array );
return $content;
}
2015-01-07 10:23:25 -08:00
add_shortcode( 'col', 'trestle_column' );
/**
* Columns.
*
2014-07-17 12:01:00 -07:00
* Example:
* [col class="one-half first no-list-margin"] Contents [/col]
*
* Classes:
* - width (one-half, one-third, etc - uses native Genesis column classes in style.css)
* - first (used to specify the first column in a row)
* - no-list-margin (will cause contained list elements to collapse as one on mobile sizes)
2015-01-07 10:23:25 -08:00
*
* @param array $atts Shortcode attributes.
*
* @return string Shortcode output.
*/
2014-01-17 17:08:19 -08:00
function trestle_column( $atts, $content = null ) {
extract( shortcode_atts( array(
2014-01-17 17:08:19 -08:00
'class' => '',
2014-11-25 13:47:18 -08:00
), $atts ) );
return '<div class="col ' . $class . '">' . do_shortcode( $content ) . '</div>';
}
2014-01-17 17:08:19 -08:00
2015-01-07 10:23:25 -08:00
add_shortcode( 'button', 'trestle_button' );
2014-07-17 12:01:00 -07:00
/**
* Button.
*
2015-01-07 10:23:25 -08:00
* Example: [button href="url" title="title" target="target" class="class"]Text[/button]
*
* @param array $atts Shortcode attributes.
*
* @return string Shortcode output.
2014-07-17 12:01:00 -07:00
*/
2014-11-21 16:03:12 -08:00
function trestle_button( $atts, $content = null ) {
2014-07-17 12:01:00 -07:00
extract( shortcode_atts( array(
2014-11-21 16:03:12 -08:00
'href' => '#',
'target' => '',
'title' => '',
'class' => '',
2014-11-25 13:47:18 -08:00
), $atts ) );
2014-11-21 16:03:12 -08:00
return '<a class="button ' . $class . '" href="' . $href . '" title="' . $title . '" target="' . $target . '">' . do_shortcode( $content ) . '</a>';
2014-07-17 12:01:00 -07:00
}
2014-11-25 13:47:18 -08:00
2015-01-07 10:23:25 -08:00
add_shortcode( 'date', 'trestle_date' );
2014-11-25 13:47:18 -08:00
/**
* Date.
2014-11-25 13:47:18 -08:00
*
* Example: [date format="M d, Y"]
2015-01-07 10:23:25 -08:00
*
* @param array $atts Shortcode attributes.
*
* @return string Shortcode output.
2014-11-25 13:47:18 -08:00
*/
function trestle_date( $atts ) {
extract( shortcode_atts( array(
'format' => 'M d, Y',
), $atts ) );
2014-11-25 13:47:18 -08:00
if ( ! $format ) {
$format = 'M d, Y';
2014-11-25 13:47:18 -08:00
}
return date( $format );
}
2015-01-07 10:23:25 -08:00
2015-04-21 12:05:22 -07:00
add_shortcode( 'blockquote', 'trestle_blockquote_shortcode' );
2015-01-07 10:23:25 -08:00
/**
* Blockquote.
*
2015-01-07 10:23:25 -08:00
* Example: [blockquote citation=""]Content[/blockquote]
*
* @since 1.2.0
*
* @param array $atts Shortcode attributes.
*
* @return string Shortcode output.
*/
2015-04-21 12:05:22 -07:00
function trestle_blockquote_shortcode( $atts, $content = null ) {
$atts = shortcode_atts( array(
'citation' => '',
), $atts );
ob_start(); ?>
<blockquote>
<?php if ( $content ) : ?>
<?php echo $content; ?>
<?php endif; ?>
<?php if ( $atts['citation'] ) : ?>
<cite>- <?php echo $atts['citation']; ?></cite>
<?php endif; ?>
</blockquote>
<?php
$output = ob_get_clean();
return $output;
2015-01-07 10:23:25 -08:00
}