G
G
Greg Plitt2020-10-26 14:09:13
Search Engine Optimization
Greg Plitt, 2020-10-26 14:09:13

How to add an open graph image for a site without a CMS?

I know that in cms plugins, it is possible to include og image randomly when it is taken for example from the text of the post, from the preview, etc.

I have a website in html, the number of pages is large. I make all mass changes through mass editing notepad ++ The
question is how to prescribe your og image to everyone, and not set the default one.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Semyon Kuznetsov, 2020-10-26
@zloy_kot_developer

It all depends on the architecture of your project. If you pull the page completely, that is, pure HTML, then in each of your pages there will be a tag, respectively.
Then you just need to add the og-image meta tag

<head>
   <title>Моя страница</title>
   <meta property="og:image" content="https://site.ru/image.png"/>
<head>

If by static pages you mean only the body of the page. For example, you have layout.php and page.php file.
Where in layout.php is the basis of the layout, and in page.php only content (body content).
Then it is possible to try global variables. For example, like this:
Code in layout.php
<head>
   <title>Моя страница</title>
   <meta property="og:image" content="<?= $GLOBALS['og_image'] ?>"/>
</head>

Code in page.php
<body>
   <?php 
       # Определяем значение глобальной переменной
       $GLOBALS['og_image'] = 'https://site.ru/image.png'
    ?>
   <h1>Моя страница</h1>
</body>

In general, it is not clear what you need, it is desirable to describe the situation with a piece of code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question