Skip to content

Instantly share code, notes, and snippets.

@davidkryzaniak
Last active December 26, 2015 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidkryzaniak/7087968 to your computer and use it in GitHub Desktop.
Save davidkryzaniak/7087968 to your computer and use it in GitHub Desktop.
WP Shortcode example
<?php
//add the shortcode
add_shortcode(
'testgetusers', //name of the shortcode [getusers]
'sample1' //the function associated with the shortcode ( get_site_users() )
);
function sample1($attributes,$content){
//make sure there is a value for each attribute
//If a value is not set, make it the default
$shortcode_values = shortcode_atts(
array('color' => '#666'),
$attributes
);
//if the content is set (not empty) wrap it in H3 tags
if(isset($content)){
echo '<h3>'.$content.'</h3>';
}
//get an array of all the users
$users = get_users();
echo '<ol style="color:' . $shortcode_values['color'] . '">';
//get the Display Name of each user, wrap it in <li>
foreach($users as $single_user){
echo '<li>' . $single_user->display_name . '</li>';
}
echo '</ol>'; //close the Ordered List
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment