Support » Themes and Templates » need to add an excpetion to filter the_excerpt for a the_content excerpt

  • Resolved kvnmcwebn

    (@kvnmcwebn)


    Hi I have an auto generated excerpt using the filter below.
    It works great. I just have one category of posts for featured images that needs to use the content for the excerpt using the <!–more–> quick tag. Right now it doesn’t work because it gets overwritten by the excerpt filter. I’d like to do this in the functions file because the loop is generated in a plug in. I tried declaring a global more but it didn’t work.

    add_filter('the_excerpt', 'excerpt_read_more_link');
    function custom_excerpt_length( $length ) {
    	return 20;
    }
    
    add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
    
    function new_excerpt_more( $excerpt ) {
    	return str_replace( '[...]', '...', $excerpt );
    }
    add_filter( 'wp_trim_excerpt', 'new_excerpt_more' );
    ?>

    tried this:

    <?php
    global $more;    // Declare global $more (before the loop).
    $more = 1;       // Set (inside the loop) to display all content, including text below more.
    the_content();
    ?>

    Here is the loop from within a plugin php file:

    if(have_posts()) : while(have_posts()) : the_post();
     ?>
     <div>
     <h2><a>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
     <div class="entry-summary">
     <?php echo strip_tags(get_the_content('Read more...')); ?>
      </div>
      <div class="slideimage"> <a>"><?php the_post_thumbnail(); ?></a>  </div>
    				</div>
     <?php
     endwhile; endif;
    
     wp_reset_query();
     ?>

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter kvnmcwebn

    (@kvnmcwebn)

    The other way I could do this is by somehow getting a different length for the excerpt needed in the featured category.

    Michael

    (@alchymyth)

    what plugin is that?

    what theme are you using?

    I am surprised that the ‘excerpt’ filter codes would have an effect on the plugin output, because it is not actually using the_excerpt().

    my opinion is that without editing the plugin, you will not get the ‘more link’ to appear in the output.

    Thread Starter kvnmcwebn

    (@kvnmcwebn)

    Hi I’m using Responsive Sticky Slider with a custom theme.
    Inside the sticky slider plugin this is what generates the post:

    <?php echo strip_tags(get_the_content()); ?>

    it was:

    <?php echo strip_tags(get_the_excerpt()); ?>

    I really wish I could do something like this:

    <?php echo strip_tags(get_the_content(100)); ?>
    or
    <?php echo strip_tags(get_the_excertp(100)); ?>

    Thread Starter kvnmcwebn

    (@kvnmcwebn)

    But yes if I use the more quick tag in the content it doesn’t work.. and the excerpt length is generated by the theme, there doesn’t seem to be anything that sets the length inside the plug in php file. Although I didn’t check the javascript. But I can control the excerpt length from the functions for the post that uses the plug in. It’s just that it’s a global thing and that post category that uses the plug in needs to have a different lenght excerpt.

    Thread Starter kvnmcwebn

    (@kvnmcwebn)

    Oh. I have been editing the loop in the plug in to add a thumbnail, simple enough because it’s a flexible and light little plugin . I was going to use metadata to add a permlink even but cant limit the word count for love nor money. Everything else has been working.

    Thread Starter kvnmcwebn

    (@kvnmcwebn)

    Here is the page, the post in question is the top featured looking post just below the header..

    http://regionalculturalcentre.com/

    Michael

    (@alchymyth)

    is it essential that you strip the tags from the content?

    if not, try to replace this line:

    <?php echo strip_tags(get_the_content()); ?>

    with:

    <?php global $more; $more = 0; the_content(); ?>

    if it is just about changing the excerpt length for a certain category, you can try to use a conditional statement in the filter code:

    add_filter('the_excerpt', 'excerpt_read_more_link');
    function custom_excerpt_length( $length ) {
    if( in_category('whatever')	 ) { return 40; }
    else { return 20; }
    }
    
    add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
    Thread Starter kvnmcwebn

    (@kvnmcwebn)

    I had thought that it was essential to use the strip tags because that was the first thing I tried. But i didn’t include the global in there, I defined it in the functions and it didn’t work. That works like a charm! Thanks a million.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘need to add an excpetion to filter the_excerpt for a the_content excerpt’ is closed to new replies.