Support

Account

Home Forums Backend Issues (wp-admin) Applying WYSIWYG Editor Component to WYSIWYG "Default Value" field

Solving

Applying WYSIWYG Editor Component to WYSIWYG "Default Value" field

  • I’d like the “Default Value” field of a WYSIWYG Editor field to actually use the WYSIWYG Editor to allow the admin to add stylized defaults.

    Has anyone done anything like this?

    Thanks for any help you can provide.

  • There isn’t any way to directly override the field type used for the default value in ACF, at least not that I can find.

    You could add a new fields setting using https://www.advancedcustomfields.com/resources/adding-custom-settings-fields/. But I don’t know that the WYSIWYG field will actually function on the ACF field group page. You would probably need to load additional scripts in order to get it to work similar to the way extra scripts need to be added to get the image field to work described here https://acfextras.com/default-image-for-image-field/

    If you can add the WYSIWYG field setting and if you can get it to work, you could then use an acf/prepare_field filter https://www.advancedcustomfields.com/resources/acfprepare_field/ to pull the value from the new setting field and put it into the standard ACF default_value for the field.

  • Much thanks for the detailed information! I’ll take a look at this over the next couple days and see if I can get it working.

    Thanks

  • // Add Script to admin
    function add_acf_wysiwyg_default_value()
    {
    ?>
        <script type="text/javascript">
            var elementID = 'Your acf div id';
            var defaultValue = '<style>.style-1 { color: red; }</style><div class="style-1">Default Value....</div>';
    
            window.onload = async function() {
                if (document.querySelector('#' + elementID)) {
                    if (document.querySelector('#' + elementID).innerHTML == '') {
                        await document.getElementById('' + elementID + '-html').click();
                        document.querySelector('#' + elementID).innerHTML = defaultValue;
                        document.getElementById('' + elementID + '-tmce').click();
                    }
                }
            }
        </script>
    <?php
    }
    add_action('admin_footer', 'add_acf_wysiwyg_default_value');
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Applying WYSIWYG Editor Component to WYSIWYG "Default Value" field’ is closed to new replies.