timothyjensen
7/2/2016 - 5:30 PM

Customize the default more link, and add that custom link to manual excerpts

Customize the default more link, and add that custom link to manual excerpts

<?php
add_filter( 'excerpt_more', 'tj_excerpt_more_link' );
/**
 * Modify the excerpt more link for standard excerpts
 *
 * @param  string, default read more link
 * @return string, modified read more link
 */
function tj_excerpt_more_link( $more ) {
    $more_link = tj_custom_more_link();

    return $more_link;
}

add_filter( 'get_the_excerpt', 'tj_manual_excerpt_more' );
/**
 * Add the custom more link to manual excerpts
 *
 * @param  string, $excerpt, manual excerpt
 * @return string, manual excerpt with appended more link
 */
function tj_manual_excerpt_more( $excerpt ) {
    if ( ! has_excerpt() )
        return $excerpt;

    $more_link = tj_custom_more_link();

    return $excerpt . $more_link;
}

/**
 * Build the custom more link
 *
 * @return string, customized more link
 */
function tj_custom_more_link() {
    $more_link = '<a class="more-link" href="' . get_permalink() . '">Read More &#46;&#46;&#46;</a>';

    return $more_link;
}

add_filter( 'excerpt_length', 'avo_excerpt_length', 999 );
/**
 * Reduce the excerpt length to 16 words
 *
 * @param $length
 * @return int
 */
function avo_excerpt_length( $length ) {
    return 16;
}