CMS Development

MartinsC
Member

Detect mobile from hubl

SOLVE

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.

 

 

0 Upvotes
1 Accepted solution
tjoyce
Solution
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

Detect mobile from hubl

SOLVE

@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 😄


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

 

Drop by and say Hi to me on slack.

View solution in original post

1 Reply 1
tjoyce
Solution
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

Detect mobile from hubl

SOLVE

@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 😄


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

 

Drop by and say Hi to me on slack.