O
O
OlegS862021-04-02 14:08:29
opencart
OlegS86, 2021-04-02 14:08:29

How to automatically detect image url on OpenCart page?

Hey!

Have a tag

<meta property="og:image" content="https://www....///...///.. .jpg" />
on all pages of the OpenCart 3.0 site

It is formed in common/header.twig with the lines:
{% if og_image %}
<meta property="og:image" content="{{ og_image }}" />
{% else %}
<meta property="og:image" content="{{ logo }}" />
{% endif %}


In controller/common/header.php sits:
if (is_file(DIR_IMAGE . $this->config->get('config_logo'))) {
      $data['logo'] = $server . 'image/' . $this->config->get('config_logo');
    } else {
      $data['logo'] = '';
    }

    $this->load->language('common/header');
    
    
    $host = isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1')) ? HTTPS_SERVER : HTTP_SERVER;
    if ($this->request->server['REQUEST_URI'] == '/') {
      $data['og_url'] = $this->url->link('common/home');
    } else {
      $data['og_url'] = $host . substr($this->request->server['REQUEST_URI'], 1, (strlen($this->request->server['REQUEST_URI'])-1));
    }
    
    $data['og_image'] = $this->document->getOgImage();


----------------------

getOgImage apparently, these are images of a category or product page (there is a module that replaces the logo in og: image with normal images in categories and product pages) .
logo is obviously a global logo.

We need a third option for information pages (controller/information), so that the first image after closing the tag would be selected in og:image Thank you. </head>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question