We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    If you want to show the different contents for Mobile and Desktop devices.
    Please follow the below code.

    Create a controller in your custom module and add the below code.
    <?php
    namespace VendorModuleControllerIndex;
    
    use MagentoFrameworkAppActionContext;
    use MagentoFrameworkViewResultPageFactory;
    
    class Devicedetect extends MagentoFrameworkAppActionAction
    {
        /**
         * @var PageFactory
         */
        protected $_pageFactory;
    
        /**
         * initialization
         *
         * @param Context $context
         * @param PageFactory $pageFactory
         */
        public function __construct(
            Context $context,
            PageFactory $pageFactory
        ) {
            $this->_pageFactory = $pageFactory;
            parent::__construct($context);
        }
        
        /**
         * Execute method
         */
        public function execute()
        {
            $resultPage = $this->_pageFactory->create();
            $userAgent  = $this->getRequest()->getHeader('useragent');
            $server     = $this->getRequest()->getServer();
             
            //Check device is Desktop
            $isDesktopDevice = Zend_Http_UserAgent_Desktop::match($userAgent, $server);
            if ($isDesktopDevice) {
                $resultPage->getConfig()->getTitle()->set(__("Desktop Detect"));
            }
            //Check device is Mobile
            $isMobileDevice = Zend_Http_UserAgent_Mobile::match($userAgent, $server);
            if ($isMobileDevice) {
                $resultPage->getConfig()->getTitle()->set(__("Mobile Detect"));
            }  
            return $resultPage;
        }
    }

     

    Fill the below form if you need any Magento relate help/advise/consulting.

    With Only Agency that provides a 24/7 emergency support.

      Get a Free Quote