Replace text on pages by using a regular expression. For example, to align the prices on a restaurant menu to the right. The regular expression in the following script replaces
<h6>First Item 20,5</h6> with <h6>First Item<span style="float: right;">20,5</span>
To be exact, it replaces the price at the end in the H6 title and replaces it with the price in a <span> that floats the price to the right. See this RegEx: <https://regex101.com/r/n85nqc/1/>
// RegEx replace - float menu prices to the right
function regex_replace($string) {
$regex = '/s([sd\]+)<\h6>/';
$replacement = '<span style="float:
right;">$1</span></h6>';
return preg_replace($regex, $replacement, $string);
}
add_filter('the_content', 'regex_replace', 9999);
Code language: PHP (php)