I am trying to figure out how to insert a php tag in between the opening and closing div tags below. Can anyone help me understand how to insert <?php the_field('200_200_1', 'option'); ?> in there?
jQuery(document).ready(function($){
$('<div class="video_gallery_ad"></div>').appendTo('#avs_gallery');
});
Edit: This is a JS file.
Edit2: Since this won't work with a JS file, I moved it into my functions.php file (using WordPress). Below is the snippet I have in my functions.php file. Is there anything wrong with this code?
jQuery(document).ready(function($){
$('<div class="video_gallery_ad"><?php the_field('200_200_1', 'option'); ?></div>').appendTo('#avs_gallery');
});
1 Answer 1
You can try with:
$('<div class="video_gallery_ad"><?php the_field('200_200_1', 'option'); ?></div>').appendTo('#avs_gallery');
But it is VERY risky. Isn't it better to render render output of this function in some hidden div and after that load its content into #avs_gallery ?
And JS:
$('#hiddenAdv').show().appendTo('#avs_gallery');
$('<div class="video_gallery_ad"><?php the_field('200_200_1', 'option'); ?></div>').appendTo('#avs_gallery');? If this is in a.phpfile, that should work (assumingthe_field()echos something).enque_script, and uselocalize_scriptto pass the PHP value. That is the proper way to do this.