Skip to content

Instantly share code, notes, and snippets.

@adamcbrewer
Created March 14, 2012 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adamcbrewer/2038220 to your computer and use it in GitHub Desktop.
Save adamcbrewer/2038220 to your computer and use it in GitHub Desktop.
WP: Adding Shortcodes To Use When Posting
<?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]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment