Post by Majna » Fri Nov 16, 2018 2:11 am

Hi

How can I add some codes in <head> </head> or <body> </body>

Can anybody help me please...........

Thank you

Active Member

Posts

Joined
Sat Jul 22, 2017 8:00 pm

Post by thekrotek » Fri Nov 16, 2018 2:25 am

Your question is strange... You just add it. If you don't even know, how to work with HTML, I wouldn't suggest you to do it yourself.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by Majna » Fri Nov 16, 2018 3:22 am

thekrotek wrote:
Fri Nov 16, 2018 2:25 am
Your question is strange... You just add it. If you don't even know, how to work with HTML, I wouldn't suggest you to do it yourself.

I am asking that are there any special module or extension in open cart to add some scripts inside head tag

Thank you

Active Member

Posts

Joined
Sat Jul 22, 2017 8:00 pm

Post by IP_CAM » Fri Nov 16, 2018 3:51 am

Well, next time, you might better look in the OC Extension Section first: ::)
Ernie
---
Custom CSS by viethemes
https://www.opencart.com/index.php?rout ... n_id=20565
Custom JavaScript by viethemes
https://www.opencart.com/index.php?rout ... n_id=20566
Add CSS Code From Admin / Backend
https://www.opencart.com/index.php?rout ... n_id=25114
Add Javascript From Admin / Backend
https://www.opencart.com/index.php?rout ... n_id=28366
Custom CSS, Javascript and Code
https://www.opencart.com/index.php?rout ... n_id=26410

My Github OC Site: https://github.com/IP-CAM
5'300 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by Johnathan » Fri Nov 16, 2018 6:04 am

If you want to manually add the code yourself, just edit your theme's header template file:

/catalog/view/theme/YOURTHEME/template/common/header.tpl

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by Majna » Sat Nov 17, 2018 5:09 pm

Johnathan wrote:
Fri Nov 16, 2018 6:04 am
If you want to manually add the code yourself, just edit your theme's header template file:

/catalog/view/theme/YOURTHEME/template/common/header.tpl

Thank you so much Johnathan

I added the code in the same location. I have a question. is it effective for all other pages like products, products category ?

Thank you

Active Member

Posts

Joined
Sat Jul 22, 2017 8:00 pm

Post by Johnathan » Mon Nov 19, 2018 10:24 pm

Yes, the header.tpl file is loaded on every single page in your site.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by Majna » Sun Dec 23, 2018 12:39 am

Johnathan wrote:
Mon Nov 19, 2018 10:24 pm
Yes, the header.tpl file is loaded on every single page in your site.

Thank you.

Active Member

Posts

Joined
Sat Jul 22, 2017 8:00 pm

Post by opencartzu » Fri Aug 05, 2022 2:57 am

hello, I would like to put a .js code before </html> for a mailerlite popup for the newsletter. I mention that I tried from the file /catalog/view/theme/fastor/template/common/header.tpl but I didn't succeed. Can someone help me? Thanks

The js code is:

<!-- MailerLite Universal -->
<script>
(function(w,d,e,u,f,l,n){w[f]=w[f]||function(){(w[f].q=w[f].q||[])
.push(arguments);},l=d.createElement(e),l.async=1,l.src=u,
n=d.getElementsByTagName(e)[0],n.parentNode.insertBefore(l,n);})
(window,document,'script','https://assets.mailerlite.com/js/universal.js','ml');
ml('account', '115781');
</script>
<!-- End MailerLite Universal -->

New member

Posts

Joined
Sun Jul 09, 2017 11:48 am

Post by hardgamer » Sun Apr 14, 2024 10:36 pm

You can use my code, in which I added also User Agent and Mobile detection:

Code: Select all


        if (isset($this->request->get['route'])) {
            $class = explode('/', $this->request->get['route']);
            $id = $class[1];
            $class = implode(' ', array_splice($class, 1));

            if (isset($this->request->get['information_id'])) {
                $this->load->model('catalog/information');
                $information_id = '_' . $this->request->get['information_id'];
                $class .= str_replace('/', '-', $information_id);
            } else if (isset($this->request->get['product_id'])) {
                $product_id = '_' . $this->request->get['product_id'];
                $class .= ' ' . str_replace('/', '-', $id . $product_id);
            } else {
                $class .= ' ' . str_replace('/', '-', $this->request->get['route']);
            }
            if (isset($this->request->get['path'])) {
                $this->load->model('catalog/category');
                $cats = explode('_', $this->request->get['path']);
                $cats = !is_array($cats) ? array($cats) : $cats;
                foreach ($cats as $cat) {
                    $model = $this->model_catalog_category->getCategory($cat);
                    $class .= ' ' . str_replace(' ', '-', preg_replace('/[^a-z0-9\s]/', '', strtolower($model['name'])));
                }
            }
        } else {
            $class = 'home common-home';
            $id = 'home';
        }

        // Detect user agent and add appropriate classes
        $user_agent = $_SERVER['HTTP_USER_AGENT'];

        // Detect browser
        if (strpos($user_agent, 'MSIE') !== false || strpos($user_agent, 'Trident') !== false) {
            $browser_class = 'ie';
        } elseif (strpos($user_agent, 'Firefox') !== false) {
            $browser_class = 'firefox';
        } elseif (strpos($user_agent, 'Chrome') !== false) {
            $browser_class = 'chrome';
        } elseif (strpos($user_agent, 'Safari') !== false) {
            $browser_class = 'safari';
        } elseif (strpos($user_agent, 'Opera') !== false || strpos($user_agent, 'OPR') !== false) {
            $browser_class = 'opera';
        } else {
            $browser_class = 'unknown-browser';
        }

        // Detect OS
        if (strpos($user_agent, 'Windows') !== false) {
            $os_class = 'windows';
        } elseif (strpos($user_agent, 'Macintosh') !== false) {
            $os_class = 'mac';
        } elseif (strpos($user_agent, 'Linux') !== false) {
            $os_class = 'linux';
        } elseif (strpos($user_agent, 'iPhone') !== false || strpos($user_agent, 'iPad') !== false) {
            $os_class = 'ios';
        } else {
            $os_class = 'unknown-os';
        }

        // Detect device (mobile or desktop)
        if (strpos($user_agent, 'Mobile') !== false) {
            $device_class = 'mobile';
        } else {
            $device_class = 'desktop';
        }

        // Concatenate all classes
        $class .= ' ' . $browser_class . ' ' . $os_class . ' ' . $device_class;
        $data['customstyle'] = ' id="' . $id . '" class="' . $class . '" ';
Put this in HEADER.PHP right before:

Code: Select all

        return $this->load->view('common/header', $data);
Then visualize in Twig with this:

Code: Select all

{{customstyle}}
For example - replace <body> with:

Code: Select all

<body {{customstyle}}>

------------------------------
Still a Noobie...
My page: http://designninja.net Graphic designer services made easy!


User avatar
Newbie

Posts

Joined
Sat Sep 06, 2014 1:21 pm
Location - Bulgaria
Who is online

Users browsing this forum: No registered users and 10 guests