How to make a H1 different then the Title?

What I want to do is… on a per page/post basis I want to be able to have the H1 say something different then the Title…

This should be such a simple thing, but I’ve been looking around for an option and searching google for a solution for an hour now, and I can’t find anything.

Read More

Is there a way to do this in WordPress without hacking the code?
Or if not, what is a clean way to do this with code that will not get overwritten when I update WordPress?

p.s. im using the Dynamik/Geneisis theme.

Related posts

2 comments

  1. Yes! Custom fields: http://codex.wordpress.org/Custom_Fields

    You can create alternate post titles via the post editor, and then you can display them with some minor adjustments to the single.php and index.php templates (or {$post_type}-archive.php templates, if you have them). For example:

    <?php $post_title = get_post_meta($post->ID, 'Post-Title', true); //"Post-Title" or whatever you call your custom field
    if ($post_title) {
    ?>
        <h1><?php echo $post_title; ?></h1>
    
    <?php } else { ?>
    
        <h1><?php the_title(); ?></h1>
    
    <?php } ?>
    

    Alex Denning has a great introduction on Smashing Magazine here: http://wp.smashingmagazine.com/2010/04/29/extend-wordpress-with-custom-fields/

    EDIT

    If you’d like to make this update-proof, I would suggest making a handy little plugin. For something to try, take the code below and replace “YOUR_CUSTOM_FIELD_HERE” with your custom field, and then it will filter the template tag the_title(); to replace it with that field (if not filled in, returns the post title). I haven’t tested this code, but it should work:

    <?php
    /**
     * Plugin Name: Replace Title With Custom Field
     * Description: When activated, this plugin replaces the title H1 with a custom field from the dashboard.
     * Version: 1.0
     * Author: penguin429
     * License: GPL2
     */
    
    function replace_title($title, $id) {
        $custom_title = get_post_meta($id, 'YOUR_CUSTOM_FIELD_HERE', true);
        $mod_title = $title;
    
        if(!empty($custom_title)) { //if field is filled in, make the title the Custom Field
            $mod_title = $custom_title;
        } else { //otherwise, return the post Title
            $mod_title = $title;
        }
        return $mod_title;
    }
    add_filter('the_title', 'replace_title', 10, 2);
    
    ?>
    

    To try it out, take the code and give it a name (say, custom-title.php) and drop it in your site’s wp-content/plugins folder and activate it. Let me know if it works out!

  2. Another easy way of doing it is installing Yoast’s SEO plugin. There you can specify an “SEO title” for each post which is the Title Tag, and then you can name the post a different thing, which would be the H1 tag in most themes.

Comments are closed.