I found a solution that works perfectly. add_settings_field
accepts an additional argument and I set the class to hidden if it shouldn’t be displayed – in this case if the value of my other setting is not “icon”. This is PHP, so it works well when the page is loaded:
add_settings_field( 'lal_add_fa', __( 'Icon font', 'login-account-logout' ), array( $this, 'lal_add_fa_callback' ), $this->settings_page_name, 'configuration_section', ( $this->lal_get_settings('lal_display_type') !== 'icon' ? array( 'class' => 'hidden' ) : array() ) );
However, I also needed a dynamic part, when the user changes the setting responsible for showing my other setting. For this, I have a js file enqueued for my plugin’s admin page only:
jQuery(document).ready(function($){
$('#lal_display_type').change(function() {
if (this.value === 'icon') {
$('#lal_add_fa').parents().eq(3).show();
} else if (this.value === 'links') {
$('#lal_add_fa').parents().eq(3).hide();
}
});
});