WordPress.org

Ready to get started?Download WordPress

Forums

Help me. How do I get the logo? (6 posts)

  1. oldcastle
    Member
    Posted 4 years ago #

    Hi,

    I need a little help here:

    Here is the situation: I'm building a WP theme and I want to check if there is a logo.png file. If this file exists, so show it. If not, display the bloginfo () function.

    So far I try something like this, but it's not working:

    [code]
    <?php
    $file = get_bloginfo('stylesheet_directory') . "/images/logo.png";
    if ($file !== FALSE) { ?>
    <img src="<?php bloginfo('template_directory'); ?>/images/logo.png" alt="Logo" />
    <?php } else { ?>
    <h1>/"><?php bloginfo('name'); ?></h1>
    <h2><?php bloginfo('description'); ?></h2>
    <?php } ?>
    [/code]

    Thanks in advance,

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 4 years ago #

    if ($file !== FALSE) is wrong.

    Try if (file_exists($file)) instead.

  3. Mxsix
    Member
    Posted 4 years ago #

    Otto is right. But also in the future, when using boolean statements, you generally only use 2 symbols at the MAX. So NOT EQUAL is "!=" and EQUAL is "==".

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 4 years ago #

    Mxsix: No, the two symbol versions test for equality, the three symbol versions test for identity.

    In PHP, zero can equal false. So can the empty string, an empty array, etc. If you want to check for an actual false only, then === or !== is the correct way to do it.

  5. Mxsix
    Member
    Posted 4 years ago #

    Thanks for the correction Otto, as soon as I posted, I thought I may have thrown out a big assumption there. Cheers.

  6. oldcastle
    Member
    Posted 4 years ago #

    Thanks for your help.

    I tried the following code, but its shows directly the bloginfo.


    <?php
    $file = get_bloginfo('stylesheet_directory') . "/images/logo.png";
    if (file_exists($file)) { ?>
    <img src="<?php bloginfo('template_directory'); ?>/images/logo.png" alt="Logo" />
    <?php } else { ?>
    <h1>/"><?php bloginfo('name'); ?></h1>
    <h2><?php bloginfo('description'); ?></h2>
    <?php } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags