Skip to content

Instantly share code, notes, and snippets.

// Display Current Year
function year_shortcode() {
$year = date('Y');
return $year;
}
add_shortcode('year', 'year_shortcode');
// First Name of Logged In User Shortcode
function ni_firstname() {
$user = wp_get_current_user();
$firstname = $user->user_firstname;
return $firstname;
}
add_shortcode('firstname', 'ni_firstname');
// Render User First Name Possessive
function ni_UserFirstName() {
global $current_user;
get_currentuserinfo();
$firstname = $current_user->user_firstname;
if (substr($current_user->user_firstname, -1) == 's') {
return $firstname . "'";
}
else
//WP Logout Button Shortcode
function ni_Logout() {
$NIlogout = wp_logout_url();
$NIlogoutbutton = '<a class="logout btn" href="'.$NIlogout.'">Logout</a>';
return $NIlogoutbutton;
}
add_shortcode('logout', 'ni_Logout');
// Set Excerpt Length and Add Ellipses
function custom_excerpt_length( $length ) {
return 30;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
function custom_excerpt_more( $more ) {
return '&hellip;';
}
// Change Read More Text in Excerpt
function et_excerpt_length($length) {
return 30;
}
add_filter('excerpt_length', 'et_excerpt_length');
/* Add link to end of excerpt in a div for styling */
function et_excerpt_more($more) {
@nathaningram
nathaningram / gist:83b32867645e477e9b16
Created December 28, 2015 02:42
Make Galleries Link to Media File Instead of Attachment Page
// Makes Gallery Images Link to Media File Instead of Attachment Page
add_shortcode( 'gallery', 'my_gallery_shortcode' );
function my_gallery_shortcode( $atts )
{
$atts['link'] = 'file';
return gallery_shortcode( $atts );
}
// Remove Customize from Admin Menu
function ni_remove_menus () {
global $submenu;
// Appearance Menu
unset($submenu['themes.php'][6]); // Customize
}
add_action('admin_menu', 'ni_remove_menus');
// Add Logout directly to admin menu
function ni_add_toolbar_items($admin_bar){
$admin_bar->add_menu( array(
'id' => 'ni-logout',
'title' => 'Log Out',
'href' => wp_logout_url()
));
}
// Prepopulate Pages and Posts with Default Content
add_filter( 'default_content', 'ni_default_editor_content' );
function ni_default_editor_content( $content ) {
global $post_type;
switch( $post_type )
{
case 'post':
$content = 'Default content for blog posts.';