stadisco
stadisco

Reputation: 557

Allowed to use a second if statement?

Am I allowed to do use a second "if" statement at the end of an existing if statement?

I am using "CODE A" to create conditional title tags for a WordPress website. Originally, "CODE A" did not include "CODE B", but I read that I could use "CODE B" by adding it towards the end of the existing if statement. Is "CODE A" correct?

Example of output of CODE A: For category "Chicken" and website name "Recipes" and "page 3":

title displayed in browser:
Chicken - Recipes - page 3

.
CODE A

<title>
<?php
if (is_category()) {
    wp_title(''); echo ' - '; } 
elseif (function_exists('is_tag') && is_tag()) {
    single_tag_title(); echo ' - '; } 
elseif (is_archive()) {
    wp_title(''); echo ' Archive - '; } 
elseif (is_page()) {
    echo wp_title(''); echo ' - '; } 
elseif (is_search()) {
    echo 'Search for &quot;'.wp_specialchars($s).'&quot; - '; } 
elseif (!(is_404()) && (is_single()) || (is_page())) {
    wp_title(''); echo ' - '; } 
elseif (is_404()) {
    echo 'Not Found - '; } 
if (is_home()) { 
    bloginfo('name'); echo ' - '; bloginfo('description'); } 
else { 
    bloginfo('name'); } 
if ($paged>1) {
     echo ' - page '. $paged; }
?>
</title>

.
CODE B: Instructions copied from a website:

Another suggestion, as I’m still tinkering with my titles is to add the page number to the end of the title if it is an archive or whatever that has multiple pages. This way you avoid any duplicate titles (which apparently are not advisable for search engines).

The code I used for this is very simple:

if ($paged>1) {
     echo '- page ', $paged;
}

I put the code right at the end after everything else.

Upvotes: 0

Views: 58

Answers (1)

Yavor
Yavor

Reputation: 671

Yes, your code is correct. Were you receiving some kind of error? The only thing you might want to remove is the "echo" in front of the third wp_title() call.

Upvotes: 2

Related Questions