A
A
Andrey2021-07-24 12:21:43
WordPress
Andrey, 2021-07-24 12:21:43

Code to output custom ACF fields?

Please tell me how to write the code correctly and implement the output of arbitrary ACF fields. If the custom field acf mobile is active, then display only custom fields acf 1,2,3,4 for mobile devices, and only custom field acf 5 for computers. If custom field acf mobile is not active, then display only acf 1 fields for all devices ,2,3,4, and do not output any field acf 5 at all.

<?php if ( get_field('mobile') ): ?>


<?php if(wp_is_mobile()) { ?>
  <?php произвольное поле acf 1 ?>

  <?php произвольное поле acf 2 ?>

  <?php произвольное поле acf 3 ?>

  <?php произвольное поле acf 4 ?>


<?php } else { ?>				
  <?php произвольное поле acf 5 ?>
<?php } ?>

<?php endif; ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yarovikov, 2021-07-24
@dyba

if ( get_field('mobile') ) {
  
  if ( wp_is_mobile() ) {		
    the_fields();	
  } else {
    acf 5
  }
  
} else {
  the_fields();
}

function the_fields() {
  acf 1 
  
  acf 2
  
  acf 3
  
  acf 4
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question