Support » Plugins » Hacks » Custom content above title outside the_content

  • stevenknight


    Hello, I have been trying to figure this out for days and I can’t.

    I would like to add a custom field when editing a post similar to how the title and content have separate fields to add custom content inside of a div above the title and outside of the_content.

    This is so I can have custom content depending on the post such as an image or YouTube video, and style it like I have for the featured posts on my homepage:

    I have been able to do it on the homepage because it relies on the post thumbnail output, something I can’t do for single posts because not all will have images (but they all will have a featured image on the homepage) I want above the title, sometimes it will be text or a YouTube video for example.

    Essentially I want a single post to be “split” up like so:

    – Custom div content
    – Title
    – Content

    Crucially, only the last 10 or so posts will need the custom div as it’s a new thing I’m doing, older posts will ignore the content div because it will be empty (or I can use some PHP to only display it on certain post IDs and above).

    I have been trying for *days* and cannot create a field to publish custom content outside of the the_content tag.

    Any help would be wonderful,


Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz


    Oddly enough, what you want to use are Custom Fields. You then would modify your templates, using the functions and tags referenced in the above article to display the custom content where ever you wish.

    If you don’t see the custom fields box in your edit screen, pull down the screen options tab and checkmark the appropriate option.



    Thank you, I tried to work with Custom Fields for about two hours a few days ago but could not good it to format how I wanted, and when I added the meta tags into my template, all custom fields were published such as Disqus ID, and the Custom Field section in Edit Post would not work properly. I’ll try again.



    I worked it out, if anyone else comes across this issue I worked it out by creating the custom field then using php if else to determine if there’s a value, and what it should output if there is or isn’t.

         <span class="blog-head"></span>
              <?php $values = get_post_custom_values("top-content");
    	        if (isset($values[0])) {
    	   <div id="top-content">
    	        <?php $values = get_post_custom_values("top-content"); echo $values[0]; ?>
    	    <h2 class="top">
                     <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    	   <?php }
    	         else { ?>
                              <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    	   <?php } ?>
    </header><!-- header ends -->
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom content above title outside the_content’ is closed to new replies.