Search code examples
google-custom-search

Change Google Custom Search layout from mobile to desktop?


I am currently developing a website that uses Google Custom Search and need to do some heavy CSS customisations. The thing is that I need it to be consistent between desktop and mobile layouts, as currently it is working fine for desktops, but looks broken on mobile phones due to the missing page numbering (on desktop it is 1 to 10, whereas on mobile it just shows: < Page 2 >).

Is there a way to trick Google CSE to always use the desktop layout, even on phones? I tried setting the UA string using Javascript in the website, but it did not work.


Solution

  • You can set the "mobileLayout" Search Element attribute to "disabled"

    See https://developers.google.com/custom-search/docs/element#supported_attributes

    example: <div class="gcse-search" data-mobileLayout="disabled"></div>