Thread Starter
gbaka
(@gbaka)
I know how to use that for post title but not sure how to do it for category…
the best i have so far is
<?php
foreach((get_the_category()) as $category) {
echo ShortenText($category->cat_name);
} ?>
shortentext being a code i have in the function, it works except every time theres a space in the name that cuts off it cuts off the whole word instead of the number of characters. this is the example of what happens
if i want for it to cut off on 7 characters
“category” it would change it to “categor…”
but if it’s this
“new category” instead of this “new cat…” it does this “new …”
Change:
echo ShortenText($category->cat_name);
to
echo substr($category->cat_name, 0, 7) . '...';
Thread Starter
gbaka
(@gbaka)
hmmm it seems to be doing that for all titles now regardless of characters length…
Thread Starter
gbaka
(@gbaka)
is there a way to use a if else statement for that tag?
Thread Starter
gbaka
(@gbaka)
oh i figured it out using the function.php thanks for the help
My original code worked i just realized that one part of it was just interfering with the spacings.
I’m trying to do something similar to this here