• Resolved Caleb Withers

    (@hoget10)


    I’m trying to have it (mainly for SEO) that on my homepage my title image is enclosed in <h1>, while on all other pages it is <h2> – the post title will be <h1> in this case.

    I tried to do it with php, but having absolutely no php knowledge, my attempt broke my page, giving a php error.

    <div id="logo">
    		<?php if (is_home()) {
    		<h1><a href="<?php echo get_option( 'home' ); ?>"><img src="<?php header_image() ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" /></a></h1>;
    		}
    		else
    		{
    		<h2><a href="<?php echo get_option( 'home' ); ?>"><img src="<?php header_image() ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" /></a></h2>;
    		}
    		?>
    		<div id="desc"><?php bloginfo( 'description' ); ?></div>
    		</div><!-- /logo -->

    Anyone know why it’s not working, or an alternative way I could achieve this?
    Cheers.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Joseph

    (@jpe24524)

    Because the html tags are inside <?php ?> and needs to be echoed.

    You can do it in a single line:

    <div id="logo">
    	<?php echo is_home() ? '<h1>' : '<h2>'; ?><a href="<?php echo get_option( 'home' ); ?>"><img src="<?php header_image() ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" /></a><?php echo is_home() ? '</h1>' : '</h2>'; ?>
    	<div id="desc"><?php bloginfo( 'description' ); ?></div>
    </div><!-- /logo -->

    Thread Starter Caleb Withers

    (@hoget10)

    Hi there,
    Thanks for that, that does the job superbly, and looks pretty efficient too.

    Joseph

    (@jpe24524)

    You’re welcome. ??

    vetteran

    (@vetteran)

    I’d like to use that too!

    Which file should that be in?

    Even less knowledge of .php than Hoget10

    Thanks in advance.

    vetteran

    (@vetteran)

    I found this in header.php (An obvious place to look!)
    Will deeply appreciate advice on what to modify.

    <div id=”branding” role=”banner”>
    <div id=”ttw-site-logo”></div>
    <div id=”ttw-site-logo-link” onclick=”location.href='<?php echo home_url( ‘/’ ); ?>’;” style=”cursor:pointer;”></div>
    <?php if (!ttw_getopt(‘ttw_hide_site_title’)){ /* TTW – hide site title */ ?>
    <?php $heading_tag = ( is_home() || is_front_page() ) ? ‘h2’ : ‘div’; ?>
    <<?php echo $heading_tag; ?> id=”site-title”>
    <span>
    ” title=”<?php echo esc_attr( get_bloginfo( ‘name’, ‘display’ ) ); ?>” rel=”home”><?php bloginfo( ‘name’ ); ?>
    </span>
    </<?php echo $heading_tag; ?>>
    <div id=”site-description”><?php bloginfo( ‘description’ ); ?></div>
    <?php } /* end hide site title if */ ?>

    Thread Starter Caleb Withers

    (@hoget10)

    What site are you trying to do this on?
    I’ve picked up a wee bit of knowledge running my site, so I could possibly come up with a solution.

    vetteran

    (@vetteran)

    Hello Caleb,

    Thank you for the king-kind offer!

    This one:

    Thread Starter Caleb Withers

    (@hoget10)

    Were you meaning to include a link?

    vetteran

    (@vetteran)

    I did!

    Hadn’t noticed that it did not work.

    Used the link button again, still won’t show
    so plain, sorry.

    https://thrush-candida-yeast-cure.com

    vetteran

    (@vetteran)

    That’s interesting, I didn’t use the link
    button but a clickable link shows.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Use H1 for title image on homepage, but H2 everywhere else’ is closed to new replies.