Web Shakehands
Web Shakehands


Use PHP to change different main pictures on different pages for WordPress

This is the third article to write the importance of changing the main picture to each page.

You can see the previous articles from the below address.

≪Set different main pictures for each page on WordPress≫

≪The importance of the main picture for WordPress≫

This time, I will write about how to set this by using PHP.

WordPress is a platform made by using PHP.
You can customize more by using this computer language.

I will explain how to set different main pictures on each page by using easy PHP code on this article.

Click "theme" from the left menu, and select "editor".

Select "Theme Header" from the right menu.

The code that is already inside the "SEO Press" theme is
<?php get_template_part( 'template-parts/header', 'headerimg' ); ?>

You will use "if" code for this.

<?php if(is_page('HOME')): ?>

The part "if" will be used to change the picture here.


this page.

the title of the website "page".

This code means,
if the title of the website page is "HOME", then show the main picture.

Now, you have set the top page main picture.

<?php endif; ?>
The part above means "if " have finished for this part.

Next, we will write a PHP code for the main picture of the sample page on the bottom.

<?php if(is_page('sample-page')): ?>

This means if the website page slag is "sample-page".

The slag is this part of the page edit.

You can write either slag or title, but you have to be careful that if you use the title, you also need to change the PHP to show the main picture.

Underneath that code, as we have done on the previous article, put the address of the main picture that we have uploaded to the media library to set inside the img tag.

This is the script that you can copy and use it for your own.
Just change the "xxxx" parts.
※This is the script for "SEOPress"
If you use different theme, the code will be different from <?php get_template_part( 'template-parts/header', 'headerimg' ); ?>

Like this, you can use PHP to change the main picture of each page.
But if you try this, you will see that the main pictures on the other pages will not appear instead of the pages that you have set.

On the next article, I will explain how to set the other pages by using PHP codes.


Newest WordPress Article !

2017-06-22 Use "BackWPup" plugin for WordPress to backup your data NEW!

2017 3/2 Make "Child Theme" for WordPress

2017 2/17 Change the main pictures of "Home, blog, sample, and the other" pages for WordPress

2017 2/02 Use PHP to change different main pictures on different pages for WordPress

2017 1/20 Set different main pictures for each page on WordPress

2017 1/5 The importance of the main picture for WordPress

Just enter your E-mail and you will receive free
mail magazine about how to make your website etc.

Go to top