Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Gone_is_my_name on "Adapt lenght of wordpress excerpt to screen width"

$
0
0

I'm making an WP theme, but I have a little problem. I want the length of excerpt (in carachters) to be adaptive to the screen width.

if screen width is bigger then 1000px, 20 characters
between 1000 and 700 it should be 5
between 700 and 640px, 20 chars
between 640 and 480, 5 chars
below 480px, 20 chars.
Hope that this makes sense. :)

I tried creating something in my functions.php. I used methods as:

function new_excerpt_length($length) {

if ((screen.width > 1024))
{
return 5;
}
else
{
return 15;
}
}
add_filter('excerpt_length', 'new_excerpt_length');

But that didn't work, it outputs the same number. CSS isn't a solution, has to be done in JS, in the functions.php file (no jQuery).


Viewing all articles
Browse latest Browse all 8245

Trending Articles