Category Archives: Programming

WordPress Logo

Add a Custom Login Logo to WordPress

Below is all you need to customise the login page of WordPress. Add it to the bottom of your functions.php.

/**
 * Custom Login Logo for WordPress
 */

add_filter( 'login_headerurl', 'tsg_login_headerurl' );
add_filter( 'login_headertext', 'tsg_login_headertext' );
add_filter( 'site_icon_image_sizes', 'tsg_site_icon_image_sizes' );
add_action( 'login_enqueue_scripts', 'tsg_login_enqueue_scripts' );

function tsg_login_headerurl()
{
    return get_bloginfo( 'url' );
}

function tsg_login_headertext()
{
    return get_bloginfo( 'name', 'display' );
}

function tsg_site_icon_image_sizes( $sizes )
{
    $sizes[] = 140;
    
    return $sizes;
}

function tsg_login_enqueue_scripts()
{
    ?>
    <style type="text/css">
        body.login div#login h1 a {
            height: 140px;
            width: 320px;
            background-image: url(<?php echo get_site_icon_url( 140, get_bloginfo( 'template_url' ) . '/images/login-logo.png' ); ?>);
            background-size: contain;
        }
    </style>
    <?php
}

There are plugins available that perform this task for you, but I don’t think it’s necessary to add a plugin just for this.

Transparent PNG format images work best.

Update 2017

I have upgraded this script to use the Site Icon. You just need to upload your image using Appearance > Customise > Site Identity.

Update 2019

WordPress deprecated ‘login_headertitle’ in favour of ‘login_headertext’.

WordPress Logo

WordPress 3.6, Read More Links Broken

My WordPress sites updated to 3.6 pretty smoothly.

Read More links for post excerpts are not being output by functions.php.

The fix is simple. Just change … to &hellip; in the filter.

/**
 * Add 'Read More' link to excerpts.
 */
add_filter( 'the_excerpt', 'tsg_excerpt_read_more_link' );
function tsg_excerpt_read_more_link( $output )
{
    global $post;
    return str_replace(' [&hellip;]', '.. <a class="read-more" href="'. get_permalink($post->ID) . '">Read More...</a>', $output);
}
WordPress Logo

WordPress Pagination Breaks when Custom Posts are Included in the Query

I’ve been using All-in-One Event Calender for a recent client project. They would like to show both recent blog posts and ai1ec_event (custom) posts in one blog feed style page.

If I disable pagination (increase the limit) they all display fine, but as soon as I enable pagination I see 404 when I try to access page 3, sometimes I can get page 2 to work. You would think if pagination was not working it would 404 on page 2 every time.

Here is the query I was trying.

$wp_query =  new WP_Query(array('post_type' => array('post', 'ai1ec_event'), 'paged' => $paged));

// Proceed with the loop.

After a few days of persistent searching, I found a similar solution for custom post types. It turned out to be a WordPress 3.4 bug.

The below code needs to be added to your functions.php if you are experiencing this bug. What triggered me to believe it isn’t the plugin, was that pagination worked fine in the search result output.

/**
 * Fixes pagination bug with WP 3.4 and the homepage when using 
 * custom post types (latest posts).
 */
add_action( 'pre_get_posts', 'custom_query_for_homepage' );
function custom_query_for_homepage( $query )
{
    if( $query->is_main_query() && $query->is_home() )
        $query->set( 'post_type', array( 'post', 'ai1ec_event' ) );
}

Hopefully this helps a few people.