• Hello,

    In my wordpress blog, I’m always starting my post with a vidéo (I’m using a shortcode from a plugin to insert the vidéos), and a download box that I programmed (so there is text inside, such as the description, and a notice).

    Then, after that, I start writing my content. It looks like that

    [Youtube=link]
    [download]Here is the amazing download box[/download}
    Here is the begenning of the content of the post.

    The problem that I have is, that wordpress (logically) uses what comes first in the post, as excerpt. For the blog listing, for the RSS feed, for any content listing in the website or sidebar. Also, when it comes to share the post on social networks (I’m using yoast SEO to spot the datas), this is what is beeing shared too. For facebook, twitter, and for some social networks, they even would share the plain code shortcode as a content.

    So the blog gets really weird, in the blog listing, every post start with “this is your download blablabla”.

    My question is, is there any way to exclude this piece of content of the post, from beeing used in that way ? I just want the text content to be displayed, not the one surrounded by html or shortcodes.

    I know there is some ways to specify which description or excerpt you want to use, but this would make me need to specify the excerpt for the blog, facebook, twitter, G+, linkedin…. (through yoast SEO) and every social network or fields I’d want it to be.

    So it would be easier if in every post, I could just tell wordpress “forget about this piece of content”, by surrounding it by a code or something.

    Is there a natural wordpress functionality that allows us to do that ? And if not; any smart plugin of your knowledge, that will make the trick ?

    Thank you in advance for your advices!
    Regards

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi estevenin,
    Write the following code in your theme’s functions.php file.

    function cedcommerce_trim_excerpt($text) {
              $text = trim($text,'[download]Here is the amazing download box[/download]');
              $text = trim($text,'[Youtube=link]');
              return $text;
    }
    add_filter('get_the_excerpt', 'cedcommerce_trim_excerpt');

    It will remove the unwanted text from your post exceprt
    Thanks

    Thread Starter estevenin

    (@estevenin)

    Hi cedcommerce,

    Thanks for your feedback ! The function has indeed made the trick, but has created another problem : now the excerpt has fallen short, just a few words are beeing displayed. I though about raising the number of characters of the excerpt, but the regular posts would also be afected so it’s not a very good option.

    Another thing for the article with this techniques, the Open Graph informations are not affected by the code, so it still takes all the information of the begenning as a description (og:description and twitter:description). For these 2, it’s even taking the “counter” of social shares, that is displayed on the top of the article below the featured image, and even the full HTML code of my download box. (The excerpt was only using the text inside of it, the social informations is taking the HTML code too)

    And since the content inside that download box and the counter are dynamics, impossible for me to exclude them all at once with a piece of code.

    That beeing said, by nature in the source code, the content of the article starts by “<div class=”itemBody>”.

    So maybe the right way would be either :

    – To be able to say to wordpress : put the “<div class=”itemBody” just after my download box. (I think this one is not very good, since it would exclude the shortcode of the video, and this one looks like it’s not beeing included in the descriptions)

    or

    – To be able to exclude the counter / download box from this div, by surrounding it by some kind of code in the article.

    I don’t know if this is possible ? Or if any kind plugin allows that ? Or… if you have (or someone else) any other solution that can make the trick for all these elements, let me know ??

    Thank you again for your feedback and your time,
    Regards

    Hi estevenin,
    You add all these shortcode ([download]Here is the amazing download box[/download] , [Youtube=link] )from dashboard?
    If you are adding all these shortcode from dashboard then its not good to exclude some content from <div class=”itemBody> wrapper.
    I think you are adding download box from single.php file using “[download]Here is the amazing download box[/download]” shortcode not from dashboard. Share your single.php file code or your site url so that I can resolve your issue
    Thanks

    Thread Starter estevenin

    (@estevenin)

    Allright thank you for your feedback.
    So this is an example of article (temporary URL) : https://urlgone.com/37b507/. (If you put /blog or /feed in the URL you might be able to see the extracts as well).

    So in this page if you check on the source code, the content of the article starts at : <div class=”itemBody .

    In order there is :
    – The featured image
    – The social counter : <div class=”essb_links (auto-generated and inserted here by a plugin)
    – The video : <div class=”su-youtube su-responsive-media-yes”>
    – The downloadboxes + download notice : <div style=”margin: 40px 0 20px;
    (followed by some css styling)

    And a bit below, the content. To answer your question, the social counter is generated and inserted here automatically by a plugin, and the video shortcode and the download HTML (and shortcode) are inserted manually inside the wordpress editor everytime I edit an article.

    And as you can see, the RSS and wordpress extracts are taking only the download text notice (thing that I could solve with the code you gave me, except for the lenght), and in the source code the Facebook Open graph and Twitter datas, are also using the numbers from the social counter, and CSS (or directly the download notice, depending on in I look at the Yoast datas or the other plugin datas above).

    So that’s the situation basically. I know there is a marked called “<before>” that you can put in the content for the extract or something like that, isn’t there a similar kind of mark to insert just before the text content to say “the actual content stars here” ? (Through a plugin or so) ? Or any other kind of solution you could see based on these informations.

    Again thank you very much for your help, very appreciated ??
    Regards

    Hi estevenin,
    You want that you can place the excerpt within some code <content>your content</content> and only that content show on excerpt. But that logic is not good because for this you need to update all your blog post and if you want that simply write your excerpt content into post excerpt section from dashboard. But it is also not good idea but its better than adding excerpt content into a wrapper.
    Thanks

    Thread Starter estevenin

    (@estevenin)

    Hi cedcommerce,

    Thanks for the follow up. I’d be fine to a “one shot” solution in every post, I don’t mind editing them all.

    I tried the <content> solution you gave me. I tried inserting it, but it seems that it doesn’t make any difference at all. Neither in the excerpt, or the og and twitter datas.

    So in order to have proper datas coming out I’d have to :
    – Fill out the excerpt field
    – Fill out the twitter description field
    – Fill out the facebook description field
    And same for G+ and pinterest.

    All with the same content :/. Any solution in mind for making it easier ?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to exclude some content from posts to be used as "excerpt"’ is closed to new replies.