Hi,
I’m trying to get 2 output from a same field (textarea or Wysiwig, don’t know which one could be best) and I would like to know if there’s a way to do this.
– If I choose textarea with no format option it will display on front end : <p>my content !</p>
– If I choose HTML option it will display : my content !
Is there a way to display both ?
Thanks for your help
Hi @Remwideco
I don’t quite understand your question. Can you please explain this with more clarity and also an explanation of why you need to get these 2 formats?
Thanks
E
Hi @elliot
Sorry if I’m not clear, English is not my natural language 🙂
I’ll try to explain what I want my users can do :
I need a field which allow my user to type a text whith format option (WYSIWIG I suppose) and I need that text to be render in 2 ways in front end :
– 1 plain text version
– 1 HTML version insert in a < pre > < code > section.
Use case is : My user type a text for example “My tailor is rich !” > on front it will render this text in 2 versions :
– 1 versions in a readable format : My tailor is rich !
– and another version in a < pre > < code > section with all html markup : < p >My tailor is < strong >rich< / strong > !< / p >
My first though was to use the WYSIWIG field type but I wonder how to make it render plain text HTML. Using a filter maybe ?
Hope this time I was more explicit 🙂 If not, will continue my investigation ^^
Hi @Remwideco
Thanks for clarifying. I think you can use the WYSIWYG field and then on your front end, do this:
<h3>Normal</h3>
<?php the_field('field_name'); ?>
<h3>Markup</h3>
<pre><?php the_field('field_name'); ?></pre>
That should work. Let me know how you go.
Thanks
E
Hi @elliot
Found with a teammate a solution. Again right in the codex 🙂
So if you want to displau the code of a Wysiwig field just use the esc_html() function.
Example :
<?php echo esc_html(get_field('my_wysiwig_field')); ?>
or (for a sub field)
<?php echo esc_html(get_sub_field('my_wysiwig_field')); ?>