Created
March 14, 2012 17:55
-
-
Save adamcbrewer/2038220 to your computer and use it in GitHub Desktop.
WP: Adding Shortcodes To Use When Posting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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