0

I'm a front-end web developer struggling with some theme option support. I am struggling to write a simple function in my header.php which allows me to do the following:

"if user uploads an image, use the image. If else use 'logo_text' and echo output. If user doesnt upload image or logo_text use default of 'My Site'"

Can anyone point me in the right direction to get started? I don't know where to begin for this one.

    <li class="name">
      <!-- Logo Text -->
      <h1><a href="<?php bloginfo('url'); ?>/home" title="<? echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
        <? $novus_logo_text = get_option('novus_logo_text'); echo $novus_logo_text; ?>
      </a></h1>
      <!-- Logo Image -->
      <a href="<?php bloginfo('url'); ?>/home" title="<? echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
        <? $novus_logo_upload = get_option('novus_logo_upload'); echo '<img class=\"logo"\ src="'.$novus_logo_upload.'" width=\"100%"\ />'; ?>
      </a>
    </li>
2
  • What would option hold if there is no upload? if ( empty( $novus_logo_upload ) {} else {} would probably do it. Note that pure PHP questions might make more sense on Stack Overflow, we mostly have stuff specific to WordPress here. :)
    – Rarst
    Jun 12, 2014 at 20:05
  • This is for a wordpress site, which is why I am asking :)! I am using ProPanel from codecanyon to handle the theme-options functions. If they do not have an upload it should default to their input for the logo_text, "My Site Name Here". If they fail to do both it defaults to std="My Site" in the function. Thanks for the quick reply! Jun 12, 2014 at 20:07

1 Answer 1

1

I posted this question on stackoverflow, and got this answer from @cmorrissey. Credit goes to him for this code.

    <?php if($novus_logo_upload = get_option('novus_logo_upload')){ ?>
      <!-- Logo Image -->
        <a href="<?php bloginfo('url'); ?>/home" title="<? echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
        <? echo '<img class=\"logo"\ src="'.$novus_logo_upload.'" width=\"100%"\ />'; ?>
        </a>
      <?php } else if($novus_logo_text = get_option('novus_logo_text')){ ?>
        <!-- Logo Text -->
        <h1><a href="<?php bloginfo('url'); ?>/home" title="<? echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
        <? echo $novus_logo_text; ?>
        </a></h1>
      <?php } else { ?>
        <!-- Default -->
        <h1><a href="<?php bloginfo('url'); ?>/home" title="<? echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"> My Site </a></h1>
      <?php } ?>
2
  • Right on the money, but I would recommend changing the line <? echo '<img class=\"logo"\ src="'.$novus_logo_upload.'" width=\"100%"\ />'; ?> to <img class="logo" src="<?php echo $novus_logo_upload; ?>" width="100%" /> Echoing markup is bad, mkay? Jun 13, 2014 at 0:10
  • You should link to that answers and credit the author Jun 13, 2014 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.