ACF Markup filter

5.0/5
<?php
add_filter('acf/format_value/key=field_608ad40710c21', function($value, $post_id, $field ) { //replace 'field_608ad40710c21' with the key of your field
	if (strpos($value, "href")) {
		return $value;
	}
	$value = preg_replace('/"(.*?)"/m', '<b>$1</b>', $value );
	$value = preg_replace('/|/m', '<br />', $value );	
	$value = preg_replace_callback('/{{(.+)}}(.+){{}}/m', fn($x) => '<a href="' . $x[1] . '" target="_blank">' . $x[2] . '</a>', $value );
	return $value;	
}, 20, 3);

Comments and reviews

{{ reviewsTotal }} Review
{{ reviewsTotal }} Reviews
{{ options.labels.newReviewButton }}
{{ userData.canReview.message }}

Description

This snippet is a showcase of filtering the value of an ACF field before it is retrieved by the get_field() function.

Author

Tags

This snippet is untagged