N
N
niknamee2021-12-02 13:44:10
WordPress
niknamee, 2021-12-02 13:44:10

How to insert an image in the header of a site?

Hello, now the image in the header of the site is added in this way

<img class="aligncenter" src="https://site. ru/wp-content/uploads/image.jpg" style="margin-bottom: 1px" alt="image" loading="lazy" width="1400" height="200" />
but it seems like it's not right and it needs to be inserted through CSS? Do not tell me how to do it? I tried following the instructions through the background image, but the header is constantly crooked. PS The header is just for appearance at the very top of the site.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2021-12-02
@pro100taa

and it needs to be inserted via CSS

What for? Who advised this?
but it doesn't seem right

Everything is fine with you.

A
Artem Zolin, 2021-12-02
@artzolin

if ( has_post_thumbnail() ) {
  $background_image = get_the_post_thumbnail_url();
} else {
  $background_image = get_stylesheet_directory_uri() . '/assets/img/default.jpg';
}

echo '<section class="section first-screen" style="background: url(' . $background_image . ') center/cover no-repeat">';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question