toastdesign
1/22/2013 - 11:42 AM

custom_shortcodes.php

<?php
/**
 * Adding shortcodes to the post-editing section: functions.php
 * http://net.tutsplus.com/tutorials/wordpress/wordpress-shortcodes-the-right-way/
 *
 **/



/**
 * REPLACING STRINGS
 *
 */
// The function
function signOffText() {
    return 'Thank you so much for reading! And remember to subscribe to our RSS feed. ';
}
// Wordpress hook
add_shortcode('signoff', 'signOffText'); 
// usage
'[signoff]'


/**
 * WRAPPING CONTENT
 *
 */
// The funtions
function quote( $atts, $content = null ) {
	return '<div class="right text">"'.$content.'"</div>';
}
// WordPress Hook
add_shortcode("quote", "quote");
// usage
'[quote]Some text[/quote]'

/**
 * ADDING ATTRIBUTES
 *
 */
// THe function
function link($atts, $content = null) {
	extract(shortcode_atts(array(
		"to" => 'http://net.tutsplus.com'
	), $atts));
	return '<a href="'.$to.'">'.$content.'</a>';
}
// WordPress Hook
add_shortcode("link", "link");
// usage
'[link to="www.net.tutsplus.com"]NetTuts+[link]'