user350530
user350530

Reputation:

PHP inside PHP Syntax and Logic

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>';}
} ?>

Upvotes: 0

Views: 277

Answers (2)

VibhaJ
VibhaJ

Reputation: 2256

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>';}
?>

Upvotes: 2

shadyyx
shadyyx

Reputation: 16055

<?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>';
}
?>

Upvotes: 0

Related Questions