90 | ‘Read more’ links for all scenarios of excerpts new

g+

When using the function ‘the_excerpt()’ in your code, WordPress by default removes all html tags, shortens the content if applicable and in this case appends those three dots … all depending on the set length limit.

There are some scenarios where no dots … get added:
– there is a hand-written excerpt;
– the cleared up content is shorter than the set lenght limit;
– there is a ‘more tag’ within the content before the set length limit.

You can customize the excerpt in some ways:
– WordPress allows to use a filter function to turn those three dots … into anything , such as a ‘read more’ link – https://developer.wordpress.org/reference/hooks/excerpt_more/;
– WordPress allows to change the set lentgth limit with a filter function – https://developer.wordpress.org/reference/hooks/excerpt_length/;
– and most interesting, it also allows to customize the whole excerpt with yet another filter function – https://developer.wordpress.org/reference/hooks/get_the_excerpt/.

If no dots … are added to the end of the excerpt, the first of those filter hooks does not work, so there is no direct way to add a ‘read more’ link in those scenarios.

Luckily, there is the filter hook ‘get_the_excerpt’ which allows to append anything – we just have to distinguish between all possible scenarios to avoid adding multiple ‘read more’ links to the excerpt…

The code:

/*
* adding the 'read more' to all scenarios of excerpts when using 'the_excerpt()' function
*/

//TURNING THE TRHEE DOTS ... INTO READ MORE LINK
add_filter('excerpt_more', 'excerpt_read_more_link');

function excerpt_read_more_link( $more ) {

	global $post;
	return '&hellip; <span class="read-more"><a href="'. get_permalink($post->ID) . '">' . __( 'Read More', 'textdomain' ) . ' &raquo;</a></span>';

}

//ADDING THE READ MORE LINK TO ALL OTHER EXCERPTS
add_filter( 'get_the_excerpt', 'excerpt_read_more_all_cases' );

function excerpt_read_more_all_cases( $text ) {

	global $post;
	$raw = $post->post_content;
	$excerpt_length = apply_filters( 'excerpt_length', 55 );
	$raw_to_more = substr( $raw, 0, strpos( $raw, '<!--more-->' ) );
	$excerpt_of_raw = wp_trim_words( $raw, $excerpt_length, ''); 
	$excerpt_of_raw_to_more = wp_trim_words( $raw_to_more, $excerpt_length, ''); 

// CHECKING FOR MANUALLY WRITTEN EXCERPT
	if( has_excerpt() ) { 
	
		$text .= '&hellip; <span class="read-more"><a href="'. get_permalink($post->ID) . '">' . __( ' manually done, so Read More', 'textdomain' ) . ' &raquo;</a></span>';
		
// CHECKING FOR EXCERPT BEING SHORT BY THE 'MORE TAG'
	} elseif( strpos( $raw, '<!--more-->' ) &amp;&amp; strlen( $excerpt_of_raw_to_more ) < strlen( $excerpt_of_raw ) ) {
	
		$text .= '&hellip; <span class="read-more"><a href="'. get_permalink($post->ID) . '">' . __( ' cut short by \'more tag\', so Read More', 'textdomain' ) . ' &raquo;</a></span>';
		
// CHECKING FOR EXCERPT BEING SHORT BECAUSE OIF SHORT CONTENT
	} elseif( strlen( $text ) == strlen( $excerpt_of_raw ) ) {
	
		$text .= '&hellip; <span class="read-more"><a href="'. get_permalink($post->ID) . '">' . __( ' too short for excerpt, but Read More anyway', 'textdomain' ) . ' &raquo;</a></span>';
		
	}
	
	return $text;
}
Posted in Tips & Tricks, Web Design | Tagged , , , , , | Not open for comments

89 | rustic hall tree – miniature

g+

It started with an idea.
And then came a pile of timber, purposefully ripped from larger boards, neatly ordered by size and stacked up nicely.

a pile of timber
timber, ready to start production

Progressing into the raw structure.
Would also look great in natural wood just treated with linseed oil.

the finished hall tree prior to painting and staining
hall tree finished before painting

Finally white washed and oiled with the hardware added.

the finished hall tree painted white with dark walnut oiled bench seat
finished hall tree painted white with dark walnut oiled bench seat

This is a little miniature doll furniture project in 1/12 scale.
The finished hall tree is just under 7 1/2 inch tall. AA battery for size comparison.

Posted in Craft and Design | Tagged , , , , , | Leave a comment

88 | Show Custom Site Title or Tagline per Page

g+

to have a custom site title and/or tagline on different pages (static pages only) of your WordPress site; one possible approach: add the code to functions.php of your theme; could also be made into a plugin as it is not … Check the whole post »

Posted in Tips & Tricks, WordPress | Tagged , , , , , | Not open for comments

87 | Better Gallery Alignment in Twenty Seventeen

g+

The new theme Twenty Seventeen shows the right thumbnail image in the default 3-column gallery with just a little space to its right,  which is particular noticable when you post a full width image directly above or below the gallery. … Check the whole post »

Posted in Tips & Tricks, Twenty Seventeen, WordPress | Tagged , , , , | Not open for comments