WordPress.org

Ready to get started?Download WordPress

Forums

PHP for wp_title brining an error on index.php (12 posts)

  1. The Music Mag
    Member
    Posted 4 years ago #

    I have a static homepage.

    I've edited the php for the h1 and h2 tags on my template. So that

    http://www.themusicmag.com/unsigned-bands

    says The Music Mag - Unsigned Bands

    and so on for the other sites. This is edited in the index.php.

    BUT my main blog page - where everything goes - doesn't recognise this for some reason. The code I'm using is bloginfo for the homepage title then wp_title for the pages title. However on the blog page it brings up "page not found"

    http://www.themusicmag.com/blog/

    Any help?

  2. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    I'm not sure that wp_title isn't going to work on your home page in this context.Have you tried using <?php the_title(); ?>?

  3. The Music Mag
    Member
    Posted 4 years ago #

    I've tried that esmi,

    But then the h1 brings up the title of the last post if i use the_title...i guess it's better than page not found, but still not ideal. I just want it to say what the page is called, like the other ones do :(

  4. The Music Mag
    Member
    Posted 4 years ago #

    I've updated it with the_title and you can see what I mean :)

  5. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    You need to edit index.php - not page.php.

    Try using:

    <?php if ( is_home() ) :
    $pp_id = get_option('page_for_posts');
    $posts_page = get_page($pp_id);
    ?>
    <h1 class="slogan2"><a href="<?php bloginfo('url');echo '/'.$posts_page->post_name;?>"><?php bloginfo('name'); wp_title(':',true,''); ?></a></h1>
    <?php endif;?>
  6. The Music Mag
    Member
    Posted 4 years ago #

    that doesn't work.

    It brings up my blog page as page not found and all the other pages have no h1 - it dissapears.

    Best i've got it is using php the_title, but then that makes the homepage have the latest blog title as the h1

  7. The Music Mag
    Member
    Posted 4 years ago #

    thank you for the help though. I tried playing about with it.

    Currently this is my h1 code on index.php

    <h1 class="slogan2">" rel="bookmark" title="<?php wp_title(); ?>"> <?php bloginfo('name'); ?> » <?php the_title(); ?></h1>

    and i think as you suggested, it needs an if function to make it so that when it's on the blog page it doesnt show the_title, but it shows "blog"

  8. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    Did you try using the code I gave above?

  9. The Music Mag
    Member
    Posted 4 years ago #

    yeah i did esmi. It didn't work. It made errors on my site and just displayed no h1 at all.

  10. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    Can I suggest you try again and make sure you add the code exactly as listed above and make sure you do not add it inside any <?php ?> tags? I've just tried that block on one of my sites and it worked fine with no errors.

  11. The Music Mag
    Member
    Posted 4 years ago #

    i think there's some problem with the template to be honest. I knew there were issues and edited some php in it - wanted to use it as loved the look - but managed to make it workable. So i think it may be some coding stuck somewhere, or some that's missing from somewhere. Maybe a stylesheet somewhere, i dont really know but

    it doesnt work.

    I've added that in the right place etc.

    blog section has "page not found"

    and the other pages now have no h1 at all - it dissapears.

  12. The Music Mag
    Member
    Posted 4 years ago #

    okay i added it before the h1 part that i already had - realised thats what i needed to do.

    And it just brings up a similar header to what there is now.

Topic Closed

This topic has been closed to new replies.

About this Topic