Answer the question
In order to leave comments, you need to log in
How to automatically (by styles, script) set color only for numbers in an article?
I have a site on Wordpress. Tell me, is it possible to somehow implement (using styles or a script) so that the numbers (just numbers) in the article are automatically painted in the color I set? That is, change the main color of not the entire text, but only the numbers, and if necessary, so that I can change the color of individual numbers to another one that is different from the main one.
Is it possible to do so, and how?
Answer the question
In order to leave comments, you need to log in
Hello!
Hang the filter on the_content, wrap the numbers in a span with the desired class in the filter using a regular expression, and set the styling in the CSS class.
(I haven't tested it, but it's probably true).
add_filter('the_content', function($content) {
return preg_replace('~(\d+)~', '<span class="colored">$1</span>', $content);
});
.colored {
color: red;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question