Skip to content

Instantly share code, notes, and snippets.

View michaeloeser's full-sized avatar

Michael Oeser michaeloeser

View GitHub Profile
@michaeloeser
michaeloeser / functions.php
Created March 19, 2016 13:21
Customize the WordPress Toolbar for non-admin Users
<?php
// Redirect to homepage after logout
add_action('wp_logout','go_home');
function go_home(){
wp_redirect( home_url() );
exit();
}
// Customize the toolbar for non admins
function change_toolbar($wp_toolbar) {
@michaeloeser
michaeloeser / limit.js
Created July 3, 2014 16:13
Limit WordPress Comments to 1000 Characters
// limit the comments to 1.000 characters
jQuery(function($) {
// configure
var comment_input = $( '#commentform textarea#comment' );
var submit_button = $( '#commentform #submit' );
var comment_limit_chars = 1000;
// stop editing here
// display how many characters are left
$( '<div class="comment_limit_info"><span>' + comment_limit_chars + '</span></div>' ).insertAfter( comment_input );
@michaeloeser
michaeloeser / functions.php
Created April 4, 2014 09:21
Modify the excerpt lenght (Wordpress default is 55 words)
<?php
//modify the excerpt lenght (Wordpress default is 55 words)
add_filter('excerpt_length', 'my_excerpt_length');
function my_excerpt_length($length) {
if (is_archive()) {
return 55; // This is the number of words in archive pages (e.g. category overview).
} else {
return 55; // This is the number of words in all other excerpts
}
}
@michaeloeser
michaeloeser / functions.php
Last active August 29, 2015 13:58
Change the appearance of the WordPress excerpt more link
<?php
// Changing excerpt more
add_filter('excerpt_more', 'new_excerpt_more');
function new_excerpt_more($more) {
return '...<br /><a class="clear excerptmore button" href="'.get_permalink().'">'. __('Continue reading' , PRiNZ_DOMAIN).' &raquo;</a><br /><br />';
}
?>
@michaeloeser
michaeloeser / functions.php
Created May 2, 2013 09:06
Login into WP with your email address instead of your username
<?php
/** Plugin Name: (#90328) Login with E-Mail address */
function login_with_email_address( $username ) {
$user = get_user_by( 'email', $username );
if ( !empty( $user->user_login ) )
$username = $user->user_login;
return $username;
}
add_action( 'wp_authenticate','login_with_email_address' );
@michaeloeser
michaeloeser / functions.php
Created April 5, 2013 13:27
Automatically link all Post Thumbnails to their Posts
// Link all Post Thumbnails to their Posts
add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );
function my_post_image_html( $html, $post_id, $post_image_id ) {
$html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html . '</a>';
return $html;
}
@michaeloeser
michaeloeser / loop.php
Created March 25, 2013 10:32
WordPress Custom Loop
<?php $custom_query = new WP_Query('cat=-9'); // exclude category 9
while($custom_query->have_posts()) : $custom_query->the_post(); ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); // reset the query ?>
@michaeloeser
michaeloeser / functions.php
Created February 25, 2013 14:17
Add "first" and "last" CSS classes to dynamic sidebar widgets
<?php
/**
* Add "first" and "last" CSS classes to dynamic sidebar widgets. Also adds numeric index class for each widget (widget-1, widget-2, etc.)
*/
function widget_first_last_classes($params) {
global $my_widget_num; // Global a counter array
$this_id = $params[0]['id']; // Get the id for the current sidebar we're processing
$arr_registered_widgets = wp_get_sidebars_widgets(); // Get an array of ALL registered widgets
if(!$my_widget_num) {// If the counter array doesn't exist, create it
$my_widget_num = array();
@michaeloeser
michaeloeser / functions.php
Created February 14, 2013 14:14
Add Custom Image Sizes Into WordPress Media Library
<?php
function display_custom_image_sizes( $sizes ) {
global $_wp_additional_image_sizes;
if ( empty($_wp_additional_image_sizes) )
return $sizes;
foreach ( $_wp_additional_image_sizes as $id => $data ) {
if ( !isset($sizes[$id]) )
$sizes[$id] = ucfirst( str_replace( '-', ' ', $id ) );
}
return $sizes;
@michaeloeser
michaeloeser / functions.php
Last active December 12, 2015 08:39
A custom WordPress Login Logo without a Plugin
<?php
function my_custom_login_logo() {
echo '<style type="text/css">
h1 a { background-image:url('.get_bloginfo('template_directory').'/images/custom-login-logo.gif) !important; }
</style>';
}
add_action('login_head', 'my_custom_login_logo');
?>