WordPress.org

Ready to get started?Download WordPress

Forums

Not sure how to use if function exists (4 posts)

  1. Patrick
    Member
    Posted 3 years ago #

    Hi there,

    I'm building a page within the admin area. I've added the option to upload a custom logo. But if no logo is uploaded I'd like the theme to use the page title.

    The code for the logo function is:

    <?php $options = get_option('plugin_options'); ?>
    <img src="<?php echo $options['logo']; ?>" alt="Logo" />

    But if no logo is uploaded, it should show:
    <a href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>

    Is this possible using if function_exists?

    Thank you so much for any advice!

  2. Patrick
    Member
    Posted 3 years ago #

    Would this work?

    <?php
    if (function_exists('plugin_options')) {
        <img src="<?php echo $options['logo']; ?>" alt="Logo" />
    } else {
        <a href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>
    }
    ?>

    I'm pretty new at this so I'd love some advice

  3. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    You're querying for an option, not for a function.

    Try this instead:

    <?php
    $options = get_option('plugin_options');
    if ( $options['logo'] ) { ?>
         <img src="<?php echo $options['logo']; ?>" alt="Logo" />
    <?php } else { ?>
         a href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>
    <?php }
    ?>
  4. Patrick
    Member
    Posted 3 years ago #

    Fantastic! That worked like a charm, thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic