• Hi,

    I have chosen to include a content warning or “trigger or warning” on some of my posts in an effort to be sensitive to my readers. I’ve done this using a described list (HTML: dt, dt, dl) inside toggle shortcode.

    My desire is that this toggle show up at the top of the post, but not in my feed on my main page. The excerpts for the feed are made using the_content in my loop-blog file and so I cut them off with the <!–more–> tag. I like deciding which posts are just excerpts so I don’t want to switch to the_excerpt.

    Is there anyway I can get this warning to appear at the top of my post without getting grabbed as part of the content? Is there some tag I can wrap it in or some easy way to fetch it only when displaying the post? I’m not a pro with wordpress or code so please be gentle.

    Here is the post, and my main feed:
    https://athirdvoice.ca/the-world-from-the-backseat/
    https://athirdvoice.ca

    Thank you generous internet mavericks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Would strip_shortcodes() do what you’re looking for:

    function sc_strip_shortcodes( $content ) {
      if ( ! is_single() ) {
        $content = strip_shortcodes( $content );
      }
    
      return $content;
    }
    add_filter( 'the_content', 'sc_strip_shortcodes' );
    Thread Starter BryceCubes

    (@brycecubes)

    This sounds good, thank you. Where do I put this?

    Since you already have a child theme, you can add the code to your functions.php. If you already have one, it’s easy, but if you don’t, don’t forget to add the opening PHP tag:

    <?php
    
    function sc_strip_shortcodes( $content ) {
      if ( ! is_single() ) {
        $content = strip_shortcodes( $content );
      }
    
      return $content;
    }
    add_filter( 'the_content', 'sc_strip_shortcodes' );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Excluding some content from automatically generated excerpt’ is closed to new replies.