Allow latex in wordpress excerpt

If I’m not mistaken, this could be as simple as add_filter(‘get_the_excerpt’, ‘latex_markup’); if the Latex markup isn’t removed by another filter before that (it shouldn’t, I believe). latex_markup is the function jetpack adds to the list of filters on the_content. It might get interesting when your latex code is at the edge of the excerpt … Read more

How to only show the first X words (from each post) on the home page?

Changing the word count on the home page is easy: if( is_home() ) add_filter( ‘excerpt_length’, create_function( ”, ‘return 300;’ ) ); Just replicate that code and change the conditional check to add this to other pages. The other option is to just insert the code on the template page (home.php, tag.php, etc.), so you know … Read more

can hyperlinks be displayed in excerpts?

WordPress uses the filter wp_trim_excerpt to strip the tags. You can remove the filter and create your own which will allow the links: <?php function new_wp_trim_excerpt($text) { $raw_excerpt = $text; if ( ” == $text ) { $text = get_the_content(”); $text = strip_shortcodes( $text ); $text = apply_filters(‘the_content’, $text); $text = str_replace(‘]]>’, ‘]]>’, $text); $text … Read more

Trim first 2 words of the exceprt

A more reliable way would be to filter the excerpt and to explode the string into an array, remove the first two key/value pairs from the array and then return your string add_filter( ‘wp_trim_excerpt’, function ( $text ) { // Make sure we have a text if ( !$text ) return $text; $text = ltrim( … Read more

Empty excerpt using wp_get_recent_posts

The post_excerpt value is empty because you have no explicit excerpts for your posts. While the_excerpt() does generate an excerpt from the posts content if the post excerpt is empty, the function wp_get_recent_posts(), which is basically a wrapper for get_posts(), doesn’t.

Read more does not show up when I write my own Excerpt

Perhaps a conditional statement like the following will work. The logic is: “If the post has an explicit excerpt, add a read more link. Otherwise, use default excerpt behavior.” if($post->post_excerpt) { the_excerpt(); echo ‘<a href=”‘.get_permalink().'”>Read More</a>’; } else { the_excerpt(); } You can use this in combination with Gavin’s suggestion to unify the appearance of … Read more