Site logo

Archived topic

Excerpt only on masonry pages

5 replies · Started by Reuben on August 23, 2015

Viewing posts 1–6 of 6

Hi there,

I'm currently using the normal blog format for the 'post' post type while I use the masonry for other custom post types. I wish to invoke the Excerpt view for masonry posts while the 'post' post type gets the full view. Is there any way to do so?

In addition, for the excerpt view, is there a way to enable emojis? For some reason, they are being stripped out in excerpt view.

Thank you!

Hi there,

This is a tough one, there's a way we can trick the post into using the more tag filter or not, but it's not ideal.

I need to add a filter so we can choose to use the excerpt or full content in certain situations.

For example:

add_filter( 'generate_more_tag', 'generate_force_excerpt' );
function generate_force_excerpt()
{
	if ( 'your-post-type' == get_post_type() ) {
		return 'false';
	} else {
		return 'true';
	}
}

Basically, that checks to see if we're on your post type - if we are, it will show the excerpt.

If we're not, it will trick the post into thinking the more tag is being used, so it will use the full content.

Not ideal, but should work.

Hi Tom,

I tried using this:

add_filter( 'generate_more_tag', 'generate_force_excerpt' );
function generate_force_excerpt()
{
	if ( is_post_type_archive( array( 'products', 'retailers' ) ) || is_tax( 'database' ) ) {
		return 'true';
	} else {
		return 'false';
	}
}

But now the full post shows on each and every post, no matter whether I have the excerpt enabled or not. Am I doing something wrong?

Thanks for the quick help by the way :)

By the way, am I right to say that the excerpt stripping out Emojis is due to WordPress and not the theme?

What the above code should do is if anything in your first if statement is true, it will show the full post regardless of any other setting.

For anything that isn't true in that statement, it should show the excerpt - is that not what's happening?

That's correct - WordPress filters out any and all HTML in the excerpt function.

There are ways to allow certain HTML in the excerpt, but it's a little complicated: http://wordpress.stackexchange.com/questions/141125/allow-html-in-excerpt

Bit late here now, but take a look at the above and let me know if you need clarification on anything :)

Thanks for the quick replies!

I tried this code

add_filter( 'generate_more_tag', 'generate_force_excerpt' );
function generate_force_excerpt()
{

		return 'false';
	
}

But it still never shows the excerpt. Changing it to return 'true' does nothing as well.

This archived topic is closed to new replies.