I have multiple WordPress site where there is an image of a logo attached to bottom of every page. Now I need it to appear only in the front page and not in the other pages.
What PHP logic and code should I use to solve this problem? I don't want to use the Widget Logic plugins. Just want to edit the PHP logic.
I believe WordPress provides is_home function which returns true if page is set as home/front page. Have a look in here: https://developer.wordpress.org/reference/functions/is_home/
if(is_home()) {
//my code attaching logo
}
In WordPress you could actually find a hook/action for a footer display and do it there. You could as well add it site-wide using apache.
You should use is_front_page() function to check if you are on homepage. If you use is_home
it will return true on blog page only.
if ( is_front_page() ) {
# code...
}
Step :1 Check post is home page
if(is_home()) {
}
Step :2 Create Shortcode for the display purpose
function mylogo() {
if(is_home()) {
echo '<img src="mylogo.png" alt="">';
}
}
add_shortcode('mylogo','mylogo');
Step :3 open footer.php or where even you want to display just use this shortcode,
In php filecode,
do_shortcode('mylogo');
In WYSWYG,
['mylogo']
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.