ThemeShaper Forums » Thematic

[closed]

H1 Tags Duplicated in Blog Description & Entry Title

(8 posts)
  • Started 2 years ago by minimal1210
  • Latest reply from minimal1210
  • This topic is not resolved
  1. minimal1210
    Member

    I'm tearing my hair out with this one... I've found a few posts that touch on the subject, but none which have the answer I need.

    The Problem:
    On a static home page, Thematic (or Wordpress) wraps both the Blog Description and the Entry Title in <h1> tags. Whilst this does not prevent anything working, it could be considered bad SEO practice.

    The Requirement:
    I need to modify either one of these to a <h2> tag, by whatever jiggerypokery available. Preferably, it would be the Entry Title and only on the home page however, as this seems to be the only place where this occurs. For other pages, it is preferable to have the reverse. So...

    Home Page - <h1>Blog Description</h1> <h2>Entry Title</h2>
    Other Pages - <div>Blog Description</div> <h1>Entry Title</h1>

    Hope this makes sense - my site is at http://macholdem.net if you would like to see what I mean. It's a poker site, so feel free to no follow or whatever - I'm not trying to promote, I just need help!

    Jim

    p.s. Thanks a squillion again for Thematic ;-)

    Posted 2 years ago #
  2. // remove duplicate h1 tag from blog description when frontpage is set to a page.
    function childtheme_override_blogdescription() {
    // silence
    }
    function childtheme_blogdescription() {
    	$blogdesc = '"blog-description">' . get_bloginfo('description');
    		if (is_home()) {
    			echo "\t\t<h1 id=$blogdesc</h1>\n\n";
    		} else {
    			echo "\t\t<div id=$blogdesc</div>\n\n";
    		}
    }
    add_action('thematic_header','childtheme_blogdescription',5);

    I don't really know php at all, so fair warning, it works though, but I always feel like I don't do it the most efficient way.

    Eventually I will figure out a way to get rid of that duplicate canonical tag too. Doubt it does anything negative for SEO but its f'in annoying. ;)

    Edited: it wasn't showing a h1 at all on "blog - home", this is now corrected.

    Posted 2 years ago #
  3. I need to learn to read, one second on the changing the h1 on blog description to a h2 instead, the code above just wraps it in a div.

    Posted 2 years ago #
  4. This will convert that frontpage blog description to an h2.

    // remove duplicate h1 tag from blog description when frontpage is set to a page and changes it to an h2.
    function childtheme_override_blogdescription() {
    // silence
    }
    function childtheme_blogdescription() {
    	$blogdesc = '"blog-description">' . get_bloginfo('description');
    		if (is_home()) {
    			echo "\t\t<h1 id=$blogdesc</h1>\n\n";
    		} elseif (is_front_page()) {
    	        echo "\t\t<h2 id=$blogdesc</h2>\n\n";
    		} else {
    			echo "\t\t<div id=$blogdesc</div>\n\n";
    		}
    }
    add_action('thematic_header','childtheme_blogdescription',5);

    But I know you are really after converting the entry-title to h2 to keep better structure, let me see about that. ;)

    Posted 2 years ago #
  5. Hmm, try this, I have never had to use conditionals like this, but it seems to work fine... Page was overriding it, but if you put the if statement inside that if it somehow works. Odd.

    function childtheme_postheader_posttitle() {
    
    	    if (is_single() || is_page()) {
    	        $posttitle = '<h1 class="entry-title">' . get_the_title() . "</h1>\n";
    			 if (is_front_page()) {
            		$posttitle = '<h2 class="entry-title">' . get_the_title() . "</h2>\n";
    			}
    	    } elseif (is_404()) {
    	        $posttitle = '<h1 class="entry-title">' . __('Not Found', 'thematic') . "</h1>\n";
    	    } else {
    	        $posttitle = '<h2 class="entry-title"><a href="';
    	        $posttitle .= apply_filters('the_permalink', get_permalink());
    	        $posttitle .= '" title="';
    	        $posttitle .= __('Permalink to ', 'thematic') . the_title_attribute('echo=0');
    	        $posttitle .= '" rel="bookmark">';
    	        $posttitle .= get_the_title();
    	        $posttitle .= "</a></h2>\n";
    		}
    	return $posttitle;
    }   
    
    add_filter('thematic_postheader_posttitle','childtheme_postheader_posttitle')

    Filters make me feel stupid sometimes, especially after using "is_frontpage" when I should have been doing "is_front_page", so I probably had it and confused myself (again) for no reason. ;x

    Posted 2 years ago #
  6. @scott- the neat thing about filters is you only have to change the sections you want to change... as long as you pass the variable through to the function as a paramete (in the parens). you don't need to copy over the entire function... in which case you may as well use the childtheme_override.

    this should only change the entry title to H2 on a static home page.

    function my_postheader_posttitle($posttitle) {
    	    if (is_front_page() && is_page()) {
    	        $posttitle = '<h2 class="entry-title">' . get_the_title() . "</h2>\n";
    	    }
        return $posttitle;
    }
    add_filter('thematic_postheader_posttitle','my_postheader_posttitle');
    Posted 2 years ago #
  7. Thanks Kathy, your example does work perfect and actually makes a ton of sense after messing with filters incorrectly. Surprisingly I haven't even had to filter too much stuff yet so I never have been forced to learn, but your example with a variable helps a ton to see how to correctly do it. ;)

    Seems like php is a lot like css, tons of different ways to do the same thing, but very few are really correct/flexible/lightweight, etc...

    Posted 2 years ago #
  8. minimal1210
    Member

    Yargh! Thank you so much guys :-) This sorted it!

    This topic is Resolved, but tell me please, where are the good resources to learn PHP for Wordpress? It baffles me!

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.