Support » Plugin: Advanced Excerpt » A separate class for the excerpt

  • pavelberg1

    (@pavelberg1)


    Hello. Is it possible to add its own class to the excerpt (inside <article> tag for example)? I tried to include like this:

    add_filter( "the_excerpt", "add_class_to_excerpt" );
    
    function add_class_to_excerpt( $excerpt ) {
        return str_replace('<article', '<article class="my-excerpt"', $excerpt);
    }

    However, it did not work out. Can you show the correct code for this? And, as it seems to me, it would be appropriate to add such a function to your wonderful plugin.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author WPKube

    (@wpkube)

    Hi @pavelberg1

    The plugin does not wrap the excerpt in a tag. If you see an article tag in there that’s coming from the theme and is 99.99% not part of the excerpt itself but it’s something like this in the theme:

    <article>
        the_excerpt();
    </article>

    But the excerpt shouldn’t be the only thing wrapped in an article tag, there should be more in there, post title should be in there as well.

    Thread Starter pavelberg1

    (@pavelberg1)

    Yes, you right. Formally, this is so. However, in reality (both for the WP user and site visitor), excerpt includes a little more than “the_excerpt” — the entire block. Depending by templates, it can be wrapped by “article” or “div”. But in any case, it is the wrapper that will be considered an excerpt. And often, with meta-tags too. It seems to me that such functionality would find application in a significant proportion of news sites and stores, at least. Because otherwise, users still have to search for all this in other plugins, or fix php/css files again and again.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.