Dropcaps in excerpts

Hello,

I’m having a problem with the Ethos theme using dropcaps. While I was configuring my site on my localhost, I put dropcaps on my posts and everything looked great. The dropcapped letters were showing up as regular text in all excerpts.

However, when I went to import the site to the live setup, the import complained about PHP versions (localhost was on PHP 5.6 and live was on 7), so I upgraded. On PHP 7.1, the front page excerpts no longer display the letter that was dropcapped.

Interestingly, the excerpts shown on other pages from a post listing plugin I use correctly display all letters in the post, so this appears to be a problem in the Ethos theme. Any ideas? Though I first noticed the problem on PHP 7.1, reverting localhost back to 5.6 has not fixed the problem, so that looks like a red herring.

Example:

Third post down on the home page, “Regenesis”, has a dropcapped first letter that doesn’t appear in the excerpt:

The same excerpt posts correctly on the author’s listing page:

I saw another support post saying that one shouldn’t expect excerpts to be able to display the dropcapped letters, as they are not really letters, but the working example above for the same post would seem to disprove this theory and point to an issue in the theme instead.

Hello There,

Thanks for writing in!

Natively in X/Pro theme, there isn’t an option to add a dropcap in the excerpts. Any shortcode added in the contents will be automatically stripped out when being displayed in the excerpts. A drop cap shortcode will be converted into an ordinary character because it is part of a paragraph. If you want to display drop caps in the excerpts you will need to install 3rd party plugin. Perhaps this could help you: https://wordpress.org/plugins/search/dropcap/

Thank you for your understanding.

I’m not trying to display the dropcap in the excerpt. The problem is that the character that was dropcapped in the post is not displaying at all as text in the excerpt.

In the example, the first word in the text is “Beyond”. In the post, the “B” is correctly dropcapped.

In the exceprt on the main page, the shortcode is not being stripped then converted into an ordinary character. The “B” is instead completely missing. So the excerpt reads “eyond”. Which is incorrect.

I’ll also note that this problem is visible in the Ethos 1 demo page itself. (See the Mens Fashion 101 excerpt)
http://demo.theme.co/ethos-1/

Hi,

Please note that the excerpt that the theme is using is a Native Wordpress function and is not in anyway modified by the theme.

You can change how it works using custom code but this would be outside the scope of support we can offer. You may wish to consult a developer to assist you with this. X is quite extensible with child themes, so there are plenty of possibilities.

Thanks for understanding. Take care!

For reference in case this helps anybody else, the fix (courtesey stackexchange) is to add the below code to the child theme’s functions.php. WP’s default trimming function uses strip_shortcodes(), which removes both shortcode tags and all content between the tags, whereas do_shortcode() removes only the tags themselves.

Presuming, of course, that you don’t have any shortcodes tags containing content you actually want removed within the excerpted length.

// FIX DROPCAPPED LETTER NOT SHOWING IN EXCERPTS
function custom_excerpt($text = '') {
    $raw_excerpt = $text;
    if ( '' == $text ) {
        $text = get_the_content('');
                // $text = strip_shortcodes( $text );
        $text = do_shortcode( $text );
        $text = apply_filters('the_content', $text);
        $text = str_replace(']]>', ']]>', $text);
        $excerpt_length = apply_filters('excerpt_length', 55);
        $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
        $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
    }
    return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
}

remove_filter( 'get_the_excerpt', 'wp_trim_excerpt'  );
add_filter( 'get_the_excerpt', 'custom_excerpt'  );
1 Like

Hello There,

Thanks for sharing this information. It’s good to know that you have figured it out a way to correct the said issue.

Best Regards.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.