Home Forums Feedback Basic textfield with simple formatting options (bold, italic, links, …)


Basic textfield with simple formatting options (bold, italic, links, …)

  • Been using ACF pretty much since the beginning, but I have always wondered why we can’t create simple, one line textfields and add basic formatting options to them like bold, italic, or links.

    I want to keep the admin as clean, simple, and clutter free as possible. But being able to add italic to text without having to write it in HTML is important to many clients. That being said, when these options become necessary for a very simple field, something in which a single word, or a simple phrase will be entered, having to transform that textfield into a WYSIWIG content editor creates a lot of clutter on the admin.

    Having the option to determine what basic options are (I’m thinking mainly bold, italic and links, options adapted to one-line text inputs) to the basic textfield would be an incredible addition!

  • Hi @brunocloutier

    For this case, you need to create a function that will convert certain patterns to certain HTML tags. You can use the preg_replace() function to do it. For example, if you want to convert the words between stars (*) into italic, you can use this code:

    $text = get_field('text');
    $pattern = '/(.*)\*(.*)\*(.*)/';
    $replacement = '$1<i>$2</i>$3';
    echo preg_replace($pattern, $replacement, $text);

    That way you can input the text like this:

    this is normal *this is italic* this is normal

    I hope this helps 🙂

  • Hi James,

    That’s one way to implement it. I was thinking about something more visual, more suitable for less tech savy users, but I’ll keep your idea in mind!

  • I just found this, maybe you should give the author of this plugin some input

  • Oh, that looks super interesting! I’ll definetely take a look.

  • I would like to have the option for a single line text field with basic styling too. For now I’ll use the acf-medium-editor plugin. Would be nice to see this integrated in ACF or ACF Pro.

  • Hi @james,

    I have inserted your code in functions.php but it doesn’t work. What would be wrong?

    Greetings and thank you

    function boldear($field) {
    	$text = get_field('usuario_pro');
    	$pattern = '/(.*)\*(.*)\*(.*)/';
    	$replacement = '$1<i>$2</i>$3';
    	//return preg_replace($pattern, $replacement, $text);
    	echo preg_replace($pattern, $replacement, $text);	
    //add_action('acf/include_field_types', 'boldear');	
    add_action('acf/render_field', 'boldear');
  • @hube2 I noticed this is yours:

    Any reason why it’s been taken down? I’d like such functionality, but I really don’t want to make my clients depend on something that is potentially out of production.

  • That plugin has not been maintained and I no longer have time to maintain it. The only reason I created it and was maintaining it is that I was using it on client sites. Recent changes to WP, ACF and Medium Editor would require a complete rebuild of the plugin, which is not something I’m going to do for a plugin that I have no plan on using.

  • Alright, fair enough. Thanks for the quick reply!

    Hopefully another similar solution gets put into the core soon.

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

The topic ‘Basic textfield with simple formatting options (bold, italic, links, …)’ is closed to new replies.