Hi @kirilb,
Thanks for reaching out!
We reviewed that code, and here are some codes that should work to hide a form on mobile:
/**
* Hide the form with ID 685 on mobile devices.
*
* @param bool $show
* @param array $form_data
* @return bool
*/
add_filter( 'wpforms_frontend_load', function( $show, $form_data ) {
if ( wp_is_mobile() && $form_data['id'] == 685 ) {
return false; // Hide the form with ID 685 on mobile devices.
}
return $show; // Show other forms and the form with ID 685 on non-mobile devices.
}, 10, 2 );
or
/**
* Hide the form on mobile devices
*
* @param bool $show
* @param array $form_data
* @return bool
*/
function my_custom_function($form, $form_data ) {
if ( wp_is_mobile() ) {
return true;
}
}
add_filter( 'wpforms_frontend_output_form_is_empty', 'my_custom_function',10,2);
In case it helps, here’s our tutorial with the most common ways to add custom code like this.
For the most beginner-friendly option in that tutorial, I’d recommend using the WPCode plugin.
Hope this helps!
Hey @kirilb – I’m Prashant filling in for my colleague Ralden 🙂
We haven’t heard back from you since the last message my colleague posted, so I’m going to go ahead and close this thread for now. But if you’d like us to assist further, please feel welcome to continue the conversation.
Thanks!
Thread Starter
kirilb
(@kirilb)
Hi, thanks, but it slightly different question. I want to hide not whole WPform form a mobile device, but only one/few field within the same form. Is that possible?
Thanks!
Hi @kirilb,
Thanks for the clarification!
Unfortunately, our filter has the $form_data parameter, but it doesn’t have a parameter to select fields. With this, we cannot use the filters above to hide only fields on mobile.
And I apologize as code customizations are outside of our scope for support.
In case you’d like to look into custom development options to hide fields on mobile, we highly recommend using Codeable.
Thanks!