Support

Account

Home Forums Front-end Issues Display ACF without child theme nor functions.php Reply To: Display ACF without child theme nor functions.php

  • One developer suggested me to add this code in a new plugin, but doesn’t work.. any suggestions?

    <?php
    
    /**
     * Plugin Name: ACF-Helper
     * Plugin URI: #
     * Description: Custom plugin for ACF.
     * Author: Monzur Alam
     * Version: 1.0.0
     * Text Domain: acf-helper
     * License: GPLv2
     * License URI: https://www.gnu.org/licenses/gpl-2.0.html
     */
    
    if (!defined('ABSPATH')) exit; // Exit if accessed directly
    
    if (!function_exists('acf_helper_content')) {
        function acf_helper_content( $content ){
            if(is_singular('post')){
                ob_start();
                ?>
                <div id="scheda-dettagli-vino" class="dettagli-vino">
                    <table>
                        <tr>
                            <td>
                                <?php 
                                    if (get_field('produttore')) {
                                        echo '<img src="/downloads/area-di-produzione.png" />', '<h3 style="display:inline; ">Area di produzione</h3>';
                                    } 
                                ?>
                            </td>
                            <td>
                                <?php 
                                    if (get_field('produttore')) {
                                        echo esc_html(the_field('produttore'));
                                    }
                                ?>
                            </td>
                        </tr>
    
                    </table>
                </div>
                <?php
                return $content . ob_get_clean();
            }
        }
        add_filter('the_content', 'acf_helper_content');
    }