Last active
December 26, 2015 03:39
-
-
Save davidkryzaniak/7087968 to your computer and use it in GitHub Desktop.
WP Shortcode example
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 | |
//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