If statement shortcode

Try this: <?php function howitworks() { $page = get_page_by_title(‘shop’); $html=””; if (have_rows(‘steps’, $page->ID)) : $html .= ‘<div class=”test”>’; while (have_rows(‘steps’, $page->ID)) : the_row(); $image = get_sub_field(‘icon’); $html .= ‘<div class=”col”> <img src=”‘.$image[‘sizes’][‘thumbnail’].'” alt=”‘.$image[‘alt’].'” title=”‘.$image[‘alt’].'” /> <h2>’.get_sub_field(‘step’).'</h2> <p>’.get_sub_field(‘description’).'</p> </div>’; endwhile; $html .= ‘</div>’; endif; return $html; } add_shortcode(‘howitworks’, ‘howitworks’); ?> EDIT: I change up my code … Read more

Gutenberg running code only available in front end within shortcode

Use it like this, this defined(‘REST_REQUEST’) will help you to disable running on the backend gutenberg block editor function generate_new_member_form() { if(defined(‘REST_REQUEST’)) return; ob_start(); ?> // a form // to generate this form there is some code that uses objects or functions // only available in the front end <?php return ob_get_clean(); } add_shortcode(‘new-member-form’, ‘generate_new_member_form’);

How to add a PHP scripts into WordPress

You could basically create a simple plugin, that will generate a shortcode. The function of this shortcode would be displaying the required images. You can choose between Ajax or maybe using the embedded PHP timer to trigger Ajax to retrieve the images. Then you embed this shortcode in your post or page (wherever you wish … Read more

Shortcode not being executed

Welcome. By using die function, You are stopping the process and it will stop immediately after running the shortcode callback. Better to let the rest of the code to be executed. You need to return something in shortcode callback function instead of sending headers using die or echo. So, change your code to something like … Read more

Advanced Custom Forms PHP formatting for do_shortcode

Even though you are echoing the shortcode, I think you still need to echo the ACF field inside the string of the do_shortcode function. Change your ACF field return function for the_field() : <?php echo do_shortcode(“[tnc-pdf-viewer-iframe file=”.the_field(‘document_link’).” width=”900px” height=”700px” download=”false” print=”false” fullscreen=”true” share=”true” zoom=”true” open=”true” pagenav=”true” logo=”true” find=”true” current_view=”true” rotate=”true” handtool=”true” doc_prop=”true” toggle_menu=”true” toggle_left=”true” scroll=”true” … Read more