0

I'm using the following which is working:

<?php if ( is_singular() ) {} else {echo '<h1>';} ?><a href="<?php echo home_url() ?>/" title="<?php bloginfo( 'name' ) ?>" rel="home"><?php bloginfo( 'name' ) ?></a><?php if ( is_singular() ) {} else {echo '</h1>';} ?>

It sets the site title as h1 and post titles to h2, unless on an individual post page, it removes the site title h1 and makes the post title an h1 header for SEO purposes.

I've added an options page to my WordPress theme which is also working for straight forward settings. Where I run into trouble is PHP inside PHP because now I want to make this a little more advanced and add a custom logo option. So if I add:

<?php $options = get_option('kittens_options'); echo $options['logo']; ?>

and connect that to the options page I can set a logo. What I want to do however, is combine these two codes into one big conditional:

<?php $options = get_option('kittens_options'); echo $options['logo'];
else {
if ( is_singular() ) {} else {echo '<h1>';}<a href="echo home_url()/" title="bloginfo( 'name' )" rel="home">bloginfo( 'name' )</a>if ( is_singular() ) {} else {echo '</h1>';}
} ?>
3
  • else { on line 2 in the last example occurs when some condition is not true, you are missing that condition. Commented May 4, 2012 at 13:24
  • The code you posted is a little confusing, can you please explain what exactly you want to do? And: You should introduce yourself into php, e.g. by reading the basics in the php manual. Commented May 4, 2012 at 13:25
  • Indentation saves you life - even if you feel hurt for your theme file, indent the code. You can move it into a function later. Commented May 4, 2012 at 13:49

2 Answers 2

2

Try this.

    <?php 
$options = get_option('kittens_options');
if (!is_singular() ) {echo '<h1>';}
echo '<a href="'.home_url().'" title="'.bloginfo( 'name' ).'" rel="home">';
    if($options['logo']!="")
        echo $options['logo'];
    else
        echo bloginfo( 'name' );
echo '</a>';
if (!is_singular() ) {echo '</h1>';}
?>
Sign up to request clarification or add additional context in comments.

1 Comment

I was able to modify this and get it working: <?php $options = get_option('kittens_options'); if (!is_singular()) {echo '<h1>';} echo '<a href="'.home_url().'/" rel="home">'; if ($options['logo']!="") echo '<img src="'.$options['logo'].'" alt="" id="logo" />'; else echo bloginfo( 'name' ); echo '</a>'; if (!is_singular() ) {echo '</h1>';} ?> The only issue was that '.bloginfo(' name ').' was breaking. I'm guessing that ' name ' needs to be escaped somehow? Thanks
0
<?php
$options = get_option('kittens_options');
echo $options['logo'];
if ( ! is_singular() ) {
    echo '<h1>';
}
echo '<a href="'.home_url().'/" title="'.bloginfo( 'name' ).'" rel="home">'.bloginfo( 'name' ).'</a>';
if ( ! is_singular() ) {
    echo '</h1>';
}
?>

Comments

Your Answer

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