WordPress.org

Ready to get started?Download WordPress

Forums

the_content() character limit (2 posts)

  1. artomal
    Member
    Posted 1 year ago #

    Hello,

    is there any way to limit characters in loop for the content f-tion? I have different post templates in the page so I want to in one place to set limit 100 characters in second place set limit 200characters at the same post like this for example:

    the_content('word to display', 'character limit');
    the_content('more', 100);

    is there any solution? Thanks

  2. vtxyzzy
    Member
    Posted 1 year ago #

    You could set a global variable with the number of characters and create a filter on the_content which would check for that global variable and truncate the content.

    However, you should be aware that truncating the content will most likely cause corrupt HTML unless you take special care to preserve it. The function the_excerpt() removes all HTML just to prevent this type of problem.

Topic Closed

This topic has been closed to new replies.

About this Topic