Support

Account

Home Forums ACF PRO Custom Preview Button Not Working Reply To: Custom Preview Button Not Working

  • I will add more accurate information.
    Added custom preview button with reference to https://rudrastyh.com/wordpress/fullscreen-preview-button.html. Custom preview buttons worked without problem until ver 5.6.
    When updating to version 5.7, clicking the button will reload the page.
    How can I solve it?

    // functions.php
    add_action('acf/input/admin_enqueue_scripts', 'my_enqueue_scripts');
    function my_enqueue_scripts()
    {
      global $pagenow;
    
      if ( 'post-new.php' == $pagenow || 'post.php' == $pagenow ) {
        wp_enqueue_script('custom-preview', get_template_directory_uri() . '/js/custom-preview.js');
      }
    }
    
    // custom-preview.js
    (function($) {
      acf.addAction('load_field/type=flexible_content', function() {
        $(document).on('click', '#custom-preview', function(e) {
          e.preventDefault();
          $('#post-preview').click();
        });
      });
    })(jQuery);