WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] remove entry-title if {home page} (18 posts)

  1. srl_frontrange
    Member
    Posted 3 years ago #

    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>

  2. srl_frontrange
    Member
    Posted 3 years ago #

  3. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    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

  4. srl_frontrange
    Member
    Posted 3 years ago #

    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?'

  5. srl_frontrange
    Member
    Posted 3 years ago #

    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!

  6. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    No problem :-)

  7. LJagermaster
    Member
    Posted 3 years ago #

    @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

  8. LJagermaster
    Member
    Posted 2 years ago #

    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

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

    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.

  10. LJagermaster
    Member
    Posted 2 years ago #

    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... :-)

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

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

  12. LJagermaster
    Member
    Posted 2 years ago #

    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... :-)

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

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

  14. LJagermaster
    Member
    Posted 2 years ago #

    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

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

    See the link I gave above.

  16. LJagermaster
    Member
    Posted 2 years ago #

    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...

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

    Until you understand the Loop and how it is implemented in your theme's template files, you are going to find it very difficult to amend any page's output. And as every theme is different, there's no standard code I can suggest.

  18. LJagermaster
    Member
    Posted 2 years ago #

    Would I be right in thinking the code you initially posted could be incorporated into the following 'if' statements (these are inside the index.php file)?:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    I tried to edit it to achieve this but I can only make guesses as to which changes should be made, and so far those guesses are causing nothing but more errors and headaches. This is what I have so far:

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

    I'd placed it just above the Category if statement and changed the category "if" to "elseif" like the ones that proceed it... Any advice on this would also appreciated...

Topic Closed

This topic has been closed to new replies.

About this Topic