You could use PHP’s preg_replace()
to wrap all the numbers (ie, any successive combination of 0
through 9
) in a <span>
tag.
add_filter( 'the_content', 'wpse426625_number_wrapper' );
/**
* Wraps any number in the content in a <span> tag.
*
* @param string $content The post content.
* @return string The content with the numbers wrapped in <span>s.
*/
function wpse426625_number_wrapper( $content ) {
$content = preg_replace(
'/(\d+)/', // \d is any digit; + matches one or more.
'<span class="numbers">$1</span>', // $1 is the text inside () in the search.
$content
);
return $content;
}
This assumes you want to wrap all the numbers in WordPress’s post content in <span>
tags; I’ve also added a class
to the spans so you can target them with CSS. If my assumptions are incorrect, I recommend you edit your question to clarify what you’re looking for.
Also note: this question is really a PHP question (or possibly a Javascript question), not a WordPress question. I’ve answered it here, but it more properly belongs on Stack Overflow.
Regular expressions (such as those used by preg_replace()
) are very powerful; if you haven’t encountered them before, you’d do well to look into how they work.