Detect mobile from hubl

SOLVE
Highlighted
New Contributor

Hi there.

 

Is there any possibility to detect mobile devices on the hubl (server) side? Like in WordPress, there' s function wp_is_mobile() which returns true or false. Or php library mobiledetect which does the same thing.

 

I am creating a custom module, a hero block and it should follow this logic:

 

If desktop -> show video as background

Else -> show image as background

 

I did not see anything like this in documentation, just wondering if it is possible. If not, will have to do it with javascript.

 

 

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Regular Advisor | Gold Partner | HubSpot Certified Trainer

@MartinsC - If you really need to do it in HUBL and you're up to the task, you can use the request headers hubl to detect the user agent and then create a switch to show relevant content:

{{request.headers['user-agent']}}

However, it's much easier to create both headers and just hide the video background section on mobile and show that version on desktop using CSS media queries

 


If this answer helped, please, mark as solved Smiley Very Happy


tim@belch.io | forms.belch.io | Design your own Beautiful HubSpot Forms; No coding necessary.

 

Drop by and say Hi to me on slack.

1 Reply
Regular Advisor | Gold Partner | HubSpot Certified Trainer

@MartinsC - If you really need to do it in HUBL and you're up to the task, you can use the request headers hubl to detect the user agent and then create a switch to show relevant content:

{{request.headers['user-agent']}}

However, it's much easier to create both headers and just hide the video background section on mobile and show that version on desktop using CSS media queries

 


If this answer helped, please, mark as solved Smiley Very Happy


tim@belch.io | forms.belch.io | Design your own Beautiful HubSpot Forms; No coding necessary.

 

Drop by and say Hi to me on slack.