The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Control wordpress excerpt length at different screen sizes

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #42453

    Hi all

    I am creating a responsive worpdress site, and would like to know if you can set a different length of excerpt text depending on screen sizes.

    So for example, on the home page for mobile phones, I would like to display 15 words for the excerpt.

    For screen width above 800px I would display 30 words.

    Above 1200px, display 50 words and so on.

    Is this possible?

    Thanks in advance.


    You’re probably going to have to use some Javascript to control this — WordPress can’t (although there might be a plugin available, haven’t checked).

    You’d have to start with setting the maximum number of words for an excerpt (say, 500). Then the Javascript would detect the screen resolution (probably upon load and screen resize), and then based on that, take off the appropriate number of words from that original 500.

    That’s the trickiest part I think, cause you’d have to convert the original 500-word excerpt into an array of words, and then take a number of elements in the array to write it out again word for word, until you reach the number of words you want.

    I wouldn’t be able to explain the full details but I would say that’s the theory behind it.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘CSS’ is closed to new topics and replies.