Page 1 of 1

Dynamic H1 Header - How?

Posted: Sat Feb 07, 2009 10:30 am
by BankNegotiator
I'm having a problem getting my Wordpress blog to generate a dynamic h1 header where I want it to.

Please Take a look at this screenshot: http://screencast.com/t/WtSrEOr8P

This cap of SEOZombie.com shows how the site owner is creating a dynamic H1 tag for his various blog posts/pages.

I'd like to have a similar setup on my blog. Here is a screencap: http://screencast.com/t/vx7TvT4xY

My idea is to put whatever targeted keywords for that page in a custom field entitled 'dynamich1" upon posting to the blog. From there I'd like to have a php call that checks to see if the "dynamich1" variable is there. If it is, it includes it there and wraps it in an h1 tag. If it is NOT there it pulls the post title and wraps it in an h1 instead.

So basically all I want this thing to do is "Check and see if there is a custom field named "dynamich1". If there IS, then diplay that here. If not, then display the post title here."

I don't know very much php and can only swipe bits and pieces from other themes to try to make it work. Here is what I tried to put in there, if no "dynamich1" was included in the post custom fields, it did properly display the blog title. But if that custom field WAS included, nothing showed.

I feel like I'm close, and that it's probably a small tweek? Possibly? Maybe. I hope.

Here's the code snippet I used:

Code: Select all

<?php if( get_post_meta($post->ID, "dynamich1", true) ): ?>
<h1 align="right"><a href="<?php echo get_post_meta($post->ID, "dynamich1", true); ?>/"></h1>
<?php else: ?>
<h1 align="right"><a href="<?php bloginfo('url'); ?>/"><?php bloginfo('name'); ?></a></h1>
<?php endif; ?>

Re: Dynamic H1 Header - How?

Posted: Sat Feb 07, 2009 1:50 pm
by JAB Creations
1.) Wrong forum.

2.) There is no such thing as a "tag", they are called elements.

3.) WordPress code is like MySpace code, any self-respecting web programmer doesn't even consider it code.

4.) WordPress has it's own forums, did you try there?

5.) Lastly I recommend the following...

Code: Select all

<h2><?php the_title(); ?></h2>

Re: Dynamic H1 Header - How?

Posted: Sun Feb 08, 2009 12:58 pm
by kaszu
Correction: there is "tag" (search this for "tag", or how about getElementsByTagName?), while I agree that he was talking about elements.