What I want to do: I want to insert a PHP file on a specific position inside the page “content”… with ACF and WP Bakery Editor.
- The website used the WP Bakery Editor
- The PHP file is in the template folder
- I created an ACF “True/False” with the fieldname “insert_slider”, and it shows on that specific page.
- I selected the field in the WP Bakery editor
- At the frontend it shows “1” (so the field is set on “true”) – so far so good
… Now I would like to output a PHP file at the point where the “1” is now.
But how i can tell the field …
if “insert_slider” is set true than <?php include_once( get_template_directory() . "/inc/mitarbeiterinterviews.php"); ?>
i’ve insert this into the page-template from this page:
<?php if ( get_field( 'insert_slider' ) ) : ?>
<?php include_once( get_template_directory() . "/inc/mitarbeiterinterviews.php"); ?>
<?php else:?>
<?php endif;?>
But it puts the slider on the position from the code inside the template file. Not on the chosen position inside the WP Bakery Editor instead of the “1”.
Wordpress: 5.9.3
PHP: 7.4.21
ACF: 5.12.2
WPBakery: 6.8.0 (Visual Composer)
This is a question for the editor you’re using and not ACF. I do not know how to include a template file with that editor.
In most cases with these editors you need to use a shortcode to do something like this. https://developer.wordpress.org/reference/functions/add_shortcode/
The shortcode would run the php code that you posted.
Unless there is something in the editor you are using that lets you add php code in the editor.
Thanks for the feedback.
I’ve already tried it with a shortcode. Unfortunately, this is executed when I save the page in the backend. Very strange. So I thought you could easily solve this with ACF. 😀