Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8682743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:51:23+00:00 2026-06-12T21:51:23+00:00

This is coming from a wordpress site I’m working on, but isn’t a WP-specific

  • 0

This is coming from a wordpress site I’m working on, but isn’t a WP-specific question.

I have an if/else PHP statement that checks whether the user is looking at my site’s home page or not. If they are looking at the home page, I want the code to do nothing. If they AREN’T, I want it to display the page title in a config.

The code I currently have is:

<div class="page-header">
  <h1>
    <?php
    if ( is_front_page()){
        echo ' ';
    }
    elseif (is_home()) {
        if (get_option('page_for_posts', true)) {
          echo get_the_title(get_option('page_for_posts', true));
        } else {
          _e('Latest Posts', 'roots');
        }
      } elseif (is_archive()) {
        $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
        if ($term) {
          echo $term->name;
        } elseif (is_post_type_archive()) {
          echo get_queried_object()->labels->name;
        } elseif (is_day()) {
          printf(__('Daily Archives: %s', 'roots'), get_the_date());
        } elseif (is_month()) {
          printf(__('Monthly Archives: %s', 'roots'), get_the_date('F Y'));
        } elseif (is_year()) {
          printf(__('Yearly Archives: %s', 'roots'), get_the_date('Y'));
        } elseif (is_author()) {
          global $post;
          $author_id = $post->post_author;
          printf(__('Author Archives: %s', 'roots'), get_the_author_meta('display_name', $author_id));
        } else {
          single_cat_title();
        }
      } elseif (is_search()) {
        printf(__('Search Results for %s', 'roots'), get_search_query());
      } elseif (is_404()) {
        _e('File Not Found', 'roots');
      } else {
        the_title();
      }
    ?>
  </h1>
</div>

I know the echo ' '; is probably way off, but I’m an absolute php beginner! At present this creates an empty <div> and <h4> tag, but I’d rather clean it up and create nothing at all on the home page.

How can I best modify the code above to achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:51:24+00:00Added an answer on June 12, 2026 at 9:51 pm

    You need to move your code around. If you don’t want the leading <div><h1> be printed on the front page, then move the if check before that. Add an else where you then print the <div><h1>, the big if/else code blob, and the closing </div>, etc.

    Also read up on switching in and out of PHPs code and html mode.
    Albeit, it’s probably best explained by just showing:

    <?php
        if ( is_front_page()){
            echo ' ';
        }
        else {
    ?>
    <div class="page-header">
      <h1>
        <?php
    
        if (is_home()) {
            if (get_option('page_for_posts', true)) {
              echo get_the_title(get_option('page_for_posts', true));
    
           /*
    
               ...
    
           */
    
          } else {
            the_title();
          }
        ?>
      </h1>
    </div>
    <?php
         }
    ?>
    

    The only interesting thing here is that you enclose the html+code blob between the elses opening { and closing } curly brace.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have data in this format coming from a database... BUS 101S Business and
I'm seeing this exception message coming from XslCompiledTransform.Transform(), but after handling the exception the
I have an image byte[] , this byte[] is coming from LDAP [Oracle Open
I am coming from c# where this was easy, and possible. I have this
I have this game where balloons are coming from bottom and player has to
I have a view model coming from the server as json like this {
I have a wordpress site, and i'm not a php developer and not very
I have a new php page and I'm using wordpress for my website. From
I have a string like this coming from an API: {\region\:{\span\:{\latitude_delta\:0.11197800000000058,\longitude_delta\:0.10020299999999338},..... What should I
I have this data coming from a REST method using jquery's getJSON method. [Date.UTC(2010,0,0,0,0,0,0),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.