WordPress.org

Support

Support » Themes and Templates » [Resolved] remove entry-title if {home page}

[Resolved] remove entry-title if {home page}

  • My php is very rusty.

    I created a static home page, but I want to remove the pesky entry-title from that page only, but still keep the Home link available in the menu.

    I figure I need an if statement to hug this bit?

    <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( __('Permalink to %s', 'your-theme'), the_title_attribute('echo=0') ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>

Viewing 15 replies - 1 through 15 (of 17 total)
  • esmi

    @esmi

    Forum Moderator

    Try:

    <?php if( !is_front_page() ):?>
    <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( __('Permalink to %s', 'your-theme'), the_title_attribute('echo=0') ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    <?php endif;?>

    http://codex.wordpress.org/Conditional_Tags

    Thank you for the link esmi. Also, thank you very much for your reply.

    I cannot seem to get this to work out though, even after I edited the syntax of your snippet. ie. colon -> semi-colon

    I have “Home” set as my static page. And “Blog” set as my posts page.

    From the Conditional Tags link you shared the warning has me wondering if this is perhaps why it’s not working for me? The action hook.

    Warning: You can only use conditional query tags on or after the init action hook in WordPress. For themes, this means the conditional tag will never work properly if you are using it in the body of functions.php, i.e. outside of a function.

    What does this mean to be ‘on or after the init action hook?’

    Oh my bad. How embarrassing. lol. I forgot to edit all the other page templates I have as well.

    No wonder I wasn’t progressing! USER ERROR! :p

    I managed to get this to work using your snippet, esmi. Thank you so much!

    esmi

    @esmi

    Forum Moderator

    No problem 🙂

    @esmi – as always there’s very little information on the codex page to explain exactly how the code is to be used. Can you explain if any of the values are to be changed, or anything added? I’ve had 1 too many bad “trial & error” type experiences with this site already and I really can’t afford any more major muck ups from now on (the project’s about to go extremely high-profile, so I need the site to be at least functional X-D )…

    Thanks in advance,

    Lee C

    LJagermaster

    @the-living-legend

    Wow, 3 months and no response. Been kept busy with so many other wordpress bugs I’d forgot to bug people about this issue! X-D

    Anyway, can someone please at least explain where the above code (posted by esmi) is to be used. There’s still very little info in the Codex pages (just looked 10 seconds ago) and this is still one of the main things holding our project back…

    Thanks again,

    LJ

    esmi

    @esmi

    Forum Moderator

    That really depends upon why/where you want to use it. I’d also suggest that, in future, you try posting a new topic as forum regulars are not going to be checking a resolved topic.

    LJagermaster

    @the-living-legend

    To be fair this topic wasn’t marked as resolved when I made my initial post, and I’ve only just noticed that it’s since been marked (if it had been before making my initial post I would naturally have started a new thread ;-p ).

    But like srl_frontrange, I’m trying to remove only the title that appears on the homepage when using a specific post as its content (using the Static Page option). If wordpress wasn’t so temperamental I’d try adding it to every possible file but I don’t trust it not completely muck up the site, again.

    Any advice would be appreciated… 🙂

    esmi

    @esmi

    Forum Moderator

    Try adding the code I gave above to your theme’s front page template file (front-page.php, home.php or page.php).

    LJagermaster

    @the-living-legend

    The only one of those I have is page.php, added the code just after <?php get_header(); ?> line (so it starts on line 2) but no changes have been made to the front page. I tried changing the ‘your-theme’ part to the name of the theme but still made no difference.

    As of yet other options I’ve came across remove the titles from all pages (via CSS classes or inline CSS) so if you come up with anymore ideas please let me know… 🙂

    esmi

    @esmi

    Forum Moderator

    You need to add it to the Loop section of the template.

    LJagermaster

    @the-living-legend

    Ok, spent the last hour trying to get this to work and so far it’s just not.

    According to the codex pages the “Loop” is between:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    and

    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

    I can see this code appear inside all 3 of the single.php, page.php & index.php files, so I added the code you provided to all 3 of them one at a time (starting with page.php, then added it to index.php and finally to single.php – each time reloading the homepage to see if any changes/errors appear, and yes I did clear the browser cache prior to each reload). As of yet no changes were made to the homepage.

    I even completely replaced the following lines in index.php with your code:

    <?php
    	if(is_home()||is_front_page()) echo '<div class="spacer"></div>';
    					<h1><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>

    after initially adding your code just below them, but it didn’t make any difference.

    @srl_frontrange – if you’re still kickin’ about can you jump back in and explain exactly where you placed the code (which files and precisely where in each file you added it, as well as any changes you made – if any)?

    @esmi – I appreciated your help but unfortunately it’s either not working on my site or I’m not following exactly what you’re saying. Until you mentioned it I had never heard of “the loop” before in this specific context. Could you maybe post or link me to an example of where the code should go (including the code that you’d expect to surround it)?

    Thanks again,

    LJ

    esmi

    @esmi

    Forum Moderator

    See the link I gave above.

    LJagermaster

    @the-living-legend

    I have read the page over (twice in fact) but still can’t quite figure out exactly how to make this work. Please understand that I’m not a highly experienced programmer (if I was I most likely wouldn;t need help with this ;-p ) so vague coding references are of very little help to me. As annoying as it is I do need a little more information than “try adding *this code* somewhere”.

    I even had a look at the “Loop In Action” but still struggling…

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘[Resolved] remove entry-title if {home page}’ is closed to new replies.
Skip to toolbar