Hi… I am using a simple function in Wordpress and it works fine. But I have a problem, I want the button to be shown according to the character limit. For example, if it is less than 100 characters, I want the button to be hidden.
Actually I tried the CSS trick but unfortunately it does not work stably across screen sizes. So I understand that PHP or JS should be used, because the button should be hidden or shown based on the character limit, not the line height.
How can I do this? Any help or ideas would be greatly appreciated, thank you.
with colors, and a little rearranging, even: ifthe length of itis more than100…
add the link.
(This is how Sam gave you the code Sam did. Translated your words into code directly. It’s something to take note of - if you can state the problem clearly enough, probably you can translate directly to code, or close to it.)
If it’s not more than 100, you dont add the link, and just return the original text.
add_filter('excerpt_length', 'my_excerpt_length');
function my_excerpt_length($length) {
return 300; } // LIMIT
It works magically without using JS. It could be improved, including text cutting features. However, for now the button will be hidden if it does not exceed the number of characters. Of course, it should be noted that the code is only supported by the Wordpress core and is a complementary function.
Note, if the content area is limited in height, the button will never appear on mobile. The important thing is that the character limit and the content height area match. You should pay attention to this in CSS. The “max-height” or height definitions can be removed if they are not needed for another definition, since they are already character limited, it does not seem necessary for this scenario.