Custom Fields for HTML Post Titles


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. 1. Enter title without HTML
  2.  
  3. 2. Create a custom field for the title with HTML
  4.  
  5. 3. Output custom field on pages you want the HTML
  6.  
  7.  
  8. For example, on the single.php page where you would have used
  9.  
  10. <h1><php the_title(); ?></h1>
  11. Now you use
  12.  
  13. <?php
  14.  
  15. $html_title = get_post_meta($post->ID, "HTML_title", true);
  16.  
  17. if ($html_title) { ?>
  18.  
  19. <h1><?php echo $html_title; ?></h1>
  20.  
  21. <?php } else { ?>
  22.  
  23. <h1><?php the_title(); ?></h1>
  24.  
  25. <?php } ?>
  26.  
  27. This checks and sees if that custom field is set. If it is, it outputs that. If not, it uses the regular function.
  28.  
  29. Because the RSS templates use the regular the_title() function, your titles are same from being weirdified in feed readers.

URL: http://digwp.com/2009/10/custom-fields-for-html-post-titles/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.