-1

I have my Flexile Content layout with custom fields:

<h2 class="mb-half"><?php the_sub_field('form_two_title')?></h2>
<p class="mb-3 lead"><?php the_sub_field('form_two_text')?></p>

and I need to write them in my custom function of functions.php witch echo.

First of all, I need to find a way to call that layout, but is it possible to write custom fields in echo section?

I have something in that way:

echo '<h2 class="mb-half">.the_sub_field('form_two_title').</h2>';

but compiler do not recognize "form_two_title" constant.

Do I need to call get_row_layout()?

mickmackusa
  • 43,625
  • 12
  • 83
  • 136
Matus Vrsansky
  • 83
  • 1
  • 10

1 Answers1

0

The code you are calling is not a valid PHP:

echo '<h2 class="mb-half">.the_sub_field('form_two_title').</h2>';

Try fixing it like this:

echo '<h2 class="mb-half">'.get_sub_field('form_two_title').'</h2>';
Jan Richter
  • 1,976
  • 4
  • 29
  • 49
  • good advice, it is working, but form_two_title is empty, do I need to call get_row_layout() ? cause that content field is on my page template. but here his values are not recognized – Matus Vrsansky Sep 24 '18 at 18:08
  • The correct syntax for your function should be described here: https://www.advancedcustomfields.com/resources/the_sub_field/ – Jan Richter Sep 24 '18 at 18:14
  • When you are using `echo` you should go for `get_sub_field`, without `echo` it is `the_sub_field`. I updated the answer. – Jan Richter Sep 24 '18 at 18:16
  • Already tried that, all get_row_layouts are in switch on my Template page, but in fucntions.php I can not write data, cause In some reason they do not exist – Matus Vrsansky Sep 24 '18 at 18:17
  • What do you mean exactly by "cannot write data"? Can you update your question with the code you have in your `functions.php` ? – Jan Richter Sep 24 '18 at 18:40
  • already solve that, but can you help me? I found problem to transform to php code in my custom class – Matus Vrsansky Sep 24 '18 at 20:49
  • please accept the answer and ask a separate question if you are having different issues. – Jan Richter Sep 24 '18 at 21:22