ACF : Reset all WYSIWYG inside a field group using JS
In this short tutorial we will learn how can be reset all the WYSIWYG with empty value using JQuery.
Search for a command to run...
In this short tutorial we will learn how can be reset all the WYSIWYG with empty value using JQuery.
No comments yet. Be the first to comment.
This series will contain code snippets & tutorials on how to customize and add a functionality in your wordpress website with the help of code. Plus coding and debugging methods that you can use.
Setup Github action for your theme in order to deploy the new version of your theme to any host with SSH access.
https://github.com/git-bhanu/scrapewave 🕷️ ScrapeWave project was created to help me accomplish some scraping tasks. The requirements of the task I was building were: To be able to access a particular link. Parse the content of the page and save...

Quickly upgrade to Ubuntu version 23.10
![How to Upgrade to a non-LTS Ubuntu [23.10] ?](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1712845921509%2F0d9f625a-85da-4e09-939e-121780145fd5.jpeg&w=3840&q=75)
Hello everyone, When I am not working at my day job, I usually surf internet and stumble upon some really good articles about tech, productivity, life and other varied topics. I would like to use this space to share them. Writing Down What I Do — In...

In this 2 min blog I will explain how easy it is to setup a webhook url and get data from any external service into your WordPress. 😉

You can find the JS code below if you are just looking for them. If you are interested in the explanation continue reading.
function bks_add_custom_js()
{
?>
<script type="text/javascript">
(function($) {
acf.add_action('ready', function( $el ){
function resetWYSIWYG(fieldGroup) {
const parent = $(fieldGroup);
const wysiwygs = parent.find('[data-type="wysiwyg"]');
$(wysiwygs).each(function(index, wysiwyg) {
let tinyID = $(this).find("textarea").attr("id");
let tinyInstance = tinyMCE.editors[tinyID];
if(tinyInstance) {
tinyInstance.setContent('');
}
});
}
// Reset all WYSIWYG for Field group haivng 'group_60d191ab7f442' id
resetWYSIWYG('#acf-group_60d191ab7f442');
});
})(jQuery);
</script>
<?php
}
add_action('acf/input/admin_footer', 'bks_add_custom_js');
We have used acf/input/admin_footer action from acf to add the custom code on the footer of our page, wherever the acf fields are shown.
Inside the function we have written our code inlined. Once the dom is ready we use action ready from ACF JS Api .
After that we define our resetWYSIWYG function. I have commented what each line does.
function resetWYSIWYG(fieldGroup) {
// Get main field group.
const parent = $(fieldGroup);
// Find all the items where data-type attribute has value of wysiwyg
const wysiwygs = parent.find('[data-type="wysiwyg"]');
// Loop around the found wysiwygs
$(wysiwygs).each(function(index, wysiwyg) {
// Find ID of the wysiwyg
let tinyID = $(this).find("textarea").attr("id");
// Get instance of tinyMCE
let tinyInstance = tinyMCE.editors[tinyID];
// If you get instance then use setContent to set the vaule empty.
if(tinyInstance) {
tinyInstance.setContent('');
}
});
}
Finally you can call the function with your group field id like so. As we are targeting id ACF adds acf- before group_key, so make sure you add that when you are specifying selector for the group.
resetWYSIWYG("#acf-group_60d191ab7f442");
I hope this snippet helped you. 😊
Let me know if you have any question below in the comment and I will try my best to answer them.