Home Forums Backend Issues (wp-admin) Using preg_replace and acf/render_field action


Using preg_replace and acf/render_field action

  • I have a function to render bold text when putting asterisks (*”*) around words/phrases.

    function make_bold($text)
      $pattern = '/(?<!\*)\*(?![\s*])(.*?)(?<![\s*])\*(?!\*)/';
      $replacement = '<strong>$1</strong>';
      echo preg_replace($pattern, $replacement, $text);
    add_action('acf/render_field/type=text', 'make_bold');

    This works as expected on the frontend.

    However, in the backend, ‘Array’ is printed under every text field – both within the custom fields editor, and page/post editors where fields are displaying.

    And without adding ‘type=text’ onto the action, ‘Array’ is printed under every field.

    So in short, why is this happening (I assume it’s the action) and how do I remove it properly?

  • acf/render_field is an action hook and there is nothing that can be filtered. This hook passes the $field array to your function. I have no idea what this is doing on the front end but it’s not doing what you think it’s doing. This hook is only run when displaying a field for input.

  • Cheers John, forget that then, I’ve just removed the action.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.