the_excerpt() with CSS (6 posts)

  1. Angela
    Posted 4 years ago #

    Hi all,

    I'm looking to make excerpts for posts that show up on my main page. Previously, I was using the_content() function, but there were many posts that I didn't manually add a read more link so now I have to resort to the_excerpt() function.

    I already have the codes and the modifications that I need. However, once I put them on, I noticed 2 problems:
    1- All the CSS in the post were gone. They are literally no new lines, no bolding, no blockquote, no nothing. How can I make the formatting to show up again?
    2- For posts that may already have read more links, it doesn't show up anymore. Rather the post looks like it ends there, no read more links.

    I'm currently resorting to use the_content() function. So, either I have to find solutions to the 2 problems above, or alternatively, I was wondering if there is an option in the_content() function to specify how many words I can display in the excerpt summary?
    I've listed my code below FYI.

    function new_excerpt_length($length) {
    	return 150;
    add_filter('excerpt_length', 'new_excerpt_length');
    function new_excerpt_more($more) {
            global $post;
    	return '<a>ID) . '"> ...Continue Reading ' . get_the_title('', '', false) . '</a>';
    add_filter('excerpt_more', 'new_excerpt_more');


    [Please post code snippets between backticks or use the code button.]

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    the_excerpt() always removes all formatting unless the post has a completed Optional Excerpt. Check Twenty Eleven's functions.php file for a function to add a read more link after excerpts.

  3. Angela
    Posted 4 years ago #

    So, um, is there a way I can add a filter to the_content() function to limit the number of words in the excerpt?

  4. esmi
    Forum Moderator
    Posted 4 years ago #

    No - the_content() and the_excerpt() are two completely separate functions.

  5. Angela
    Posted 4 years ago #

    I understand, but doesn't the_content() function also provide excerpt function? (such as editing the 'read more' text? My only question is, can I use it to create a short excerpt that keeps the formatting and limit the amount of words available in the excerpt as well?

  6. chadrew
    Posted 4 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic