How can I change the post format when a particular category is selected?

It used to be really easy to do this. Just stick a little jQuery in admin_footer. But that doesn’t work any more, thanks to Gutenberg.

Here’s the functionality I need to reproduce:

add_action( ‘admin_footer’, function(){
?>
<script>
(function($) {
$(function() {
$(‘body’).on(‘change’, ‘#editor-post-taxonomies-hierarchical-term-14’, function(){
if( $(this).is(‘:checked’) ) {
$(‘#post-format-selector-0’).val(‘link’);
} else {
$(‘#post-format-selector-0’).val(‘standard’);
}
});
});
})(jQuery);
</script>
<?php
} );

The post format is changed, but when you save the post, it reverts back. 🙁

Read more here:: How can I change the post format when a particular category is selected?

Leave a Reply

Your email address will not be published. Required fields are marked *