How to replace special words within posts from wordpress multisites
Briefly

How to replace special words within posts from wordpress multisites
"I have a WordPress multisite, and I am using a plugin (Broadcast) to send the same post from my main site to all of the sub-sites at the same time. I want to replace a word within the post based on each sub-site. For example: If the main site post includes 'london', replace 'london' with 'sydney' in my domain/sydney subsite. Replace 'London' with 'Auckland' in my domain/auckland subsite."
"A common approach is to hook into the_content filter and run a simple string replacement based on the current site ID or domain. In a multisite setup, you can check which subsite is rendering the post and then apply str_replace() (or a mapping array) before the content is displayed. This keeps the original post intact while customizing output per site."
Add a filter on the_content to modify post HTML when each subsite renders it. Detect the current site by get_current_blog_id(), get_blog_details()->path, or domain and choose a replacement mapping keyed by blog ID, slug, or domain. Use str_replace(), str_ireplace(), or preg_replace('/\bword\b/i') for whole-word and case-sensitive handling. Place the code in a mu-plugin or the child theme to ensure it runs on every subsite. Avoid changing stored posts; perform replacements on output only. Consider performance, escaping HTML, shortcode handling, and preserving original capitalization when creating mappings.
[
|
]