Function extension

The issue arises because str_replace() is replacing partial matches (like “POA” inside “POA (+)”). To fix this and ensure only exact matches are replaced, we can switch to using regular expressions with preg_replace(). Here’s a refined version of your function: function auto_link_post_titles( $content, $post_id, $field ) { $excluded_ids = array(); $excluded_field_names = array(); if ( … Read more

When a foreach loop is used multiple times in blocks, is there a way to ensure a variable always has a unique value?

You could consider wp_unique_id(): This is a PHP implementation of Underscore’s uniqueId method. A static variable contains an integer that is incremented with each call. This number is returned with the optional prefix. As such the returned value is not universally unique, but it is unique across the life of the PHP process. Even if … Read more