WordPress.org

Forums

Image Caption Being Pulled into Excerpt? (9 posts)

  1. overdoseonjenny
    Member
    Posted 3 years ago #

    Hi,

    My website is obsessandconsume.com. I have a post in there, a review for a movie. On the single post page, i have two images. I added captions to them. For example, under one image i added "there's tons of red symbolism in the film."

    On my front page, I have thumbnails and excerpts of all my articles. On this particular post, the excerpt text is PULLING the image caption "there's tons of red symbolism in the film" so literally when a person goes to my homepage and tries to read whatthe review is about, get a taste of it, first thing they read is "there's tons of red symbolism."

    I don't want that to happen. How can I get the excerpt to not do that. Thanks.

  2. Jonas Grumby
    Member
    Posted 3 years ago #

    By default the excerpt shows the first 55 words it finds. You can enter the excerpt manually into the dialog box on the add/edit post screen if you don't want it to do that.

  3. overdoseonjenny
    Member
    Posted 3 years ago #

    Damn I didn't want to enter it manually, I have everything set up in my functions.php a certain way so it'll look good. UGHHH. I found this, do you know anything about it?

    1. From what I understand the caption is a shortcode, so wrap get_the_content(...) inside strip_shortcodes() and it should remove it.

    2. You can always simply hide it with CSS. It's not a perfect solution but may be sufficient for your case. CSS class of the caption paragraph is .wp-caption-text.

    I tried the second one, but i have to mess with it. I don't really understand how to do #1.

  4. Jonas Grumby
    Member
    Posted 3 years ago #

    I have never done #1 but there is good info here and it seems pretty straightforward.

    http://codex.wordpress.org/Function_Reference/strip_shortcodes

    With #2 you could use CSS to set visibility: hidden; for .wp-caption-text

  5. overdoseonjenny
    Member
    Posted 3 years ago #

    Hmm.. using codex, I added this:

    // Removes shortcodes from post excerpts
    function remove_shortcode_from_index($content) {
    if ( is_home() ) {
    $content = strip_shortcodes( $content );
    }
    return $content;
    }
    add_filter('the_content', 'remove_shortcode_from_index');

    ..to my functions.php file. Doesn't seem to be removing anything though.. I also did #2, that didn't work either.. but I didn't remove the code from functions.php before I did it. They are both there together.

  6. Jonas Grumby
    Member
    Posted 3 years ago #

    Keep in mind that is_home will only work if the home page is the main blog page in Settings > Reading. If you have selected "a static page" you would have to use is_front-page

  7. overdoseonjenny
    Member
    Posted 3 years ago #

    Yes I don't use a static page. _home should be ok to use. I wish the CSS thing would just work it would be much less complicated. But thank you for all your help.

  8. Jonas Grumby
    Member
    Posted 3 years ago #

    Also, Firebug & page source do not show that text as having any .wp-caption class.

  9. Jonas Grumby
    Member
    Posted 3 years ago #

    The reason you can't do it with CSS is because that text is not being assigned a separate CSS class.

Topic Closed

This topic has been closed to new replies.

About this Topic