>\" text from the title only on the homepage. Here is the code that i\'m working with:" />
开发者

Website Title Help

I'm working on adjusting my site title in Wordpress. I want my site title to admit the "Home >>" text from the title only on the homepage. Here is the code that i'm working with:

<title><?php if ( is_home() ) { ?> <?php } ?>  <?php echo ucwords(wp_title('',false)); ?> &raquo; <?php echo ucwords(get_bloginfo('name')); ?>  </title>

As i'm new to php, I'm trying decypher the coding. Would an if-else statement serve better?

 <title><?php if ( is_home() ) 
                echo "Blah blah blah";
              else
                echo "<?php echo ucwords(wp_title('',false)); ?>
   &raquo; <?php echo      
   ucwords(get_bloginfo('name')); ?>";
 ?></title>


{ ?> <?php } ?> 
    <?php echo ucwords(wp_title('',false)); ?> &raquo; <?php echo ucwords(get_bloginfo('name')); ?>开发者_如何学Go 
</title>

I would greatly appreciate your opinion. My website is http://www.merrimentdesign.com


<title>
<?php if ( is_home() ) { ?> Home title, you don't need to echo something <?php } ?>
<?php echo ucwords(wp_title('',false)); ?> &raquo; 
<?php echo ucwords(get_bloginfo('name')); ?>  
</title>

Edit:

<title>
    <?php 
         if ( is_home() ) { //I'm in the homepage 
    ?> 
             Home title, you don't need to echo something
    <?php
        }else{ //every page but homepage
            echo ucwords(wp_title('',false)) . '&raquo;' . ucwords(get_bloginfo('name'));
        }
    ?>
</title>


An inline comparison would serve you well

<title>
<?php 
echo (ishome()? "isHome evaluated to true": "isHome evaluated to false");
?>
</title>

Additionally nested PHP tags will not work and will simply throw errors.

IE

<?PHP
//everything in here is already php, if you add this:
echo "echo <?php doSomething(); ?>";
?>

Will not work because the ?> tag within your "echo" statement will be treated by PHP as the end of the PHP code block, not a string literal.


Instead of

echo "<?php echo ucwords(wp_title('',false));

just do

echo ucwords(wp_title('',false));

You can't echo PHP tags and have them be executed as PHP code.


That's what I do in my blog. But it won't work like it is - change it to:

<title><?php if ( is_home() )
                 echo "Blah blah blah";
             else
                 echo ucwords(wp_title('',false)); ?>    
&raquo; 

<?php echo ucwords(get_bloginfo('name')); ?></title> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜