2

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.

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.

2

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!

  • 1
    Thanks, before I persue this option though: is the method update proof? i.e. when I update my theme will those files that I customized not be overwritten? – Jan Paul Mar 7 '14 at 5:53
  • Just editing the template files would not be theme update proof. See edit above for a plugin idea. A plugin would bypass any theme or WP updates. I hope this helps! – penguin429 Mar 7 '14 at 6:21
-1

You'll need to do this through the php templates of your theme.

You may have a Page template and/or an index.php template (and/or it could be elsewhere!) with a line such as:

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

You simply need to remove this. Then headings can be added back manually on any page/post.

  • Ok thanks, but won't this be overwritten everytime I update the theme? – Jan Paul Mar 7 '14 at 5:09
  • Yes, this will be be overwritten when/if you update the theme. So in that case you should make a child theme and apply that so that the changes stick. You only need to duplicate the one or two relevant php files into your child theme and leave the rest as is. – Monkey Puzzle Mar 7 '14 at 5:50
-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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.