• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Add page and post specific content between title and content

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add page and post specific content between title and content

This topic is: resolved
  • This topic has 9 replies, 2 voices, and was last updated 12 years, 10 months ago by Brad Dalton.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • May 18, 2013 at 12:16 am #41473
    csbeck
    Member

    I have a website (testing PAGE - http://acquireb2bdev.com/products) that the client wants to have some custom content on each page and perhaps each post between the title and the content of the page. I'm using Agency for the child theme.

    Thanks to Brad Dalton who helped hook some content between the title and the content (http://www.studiopress.community/topic/add-excerpt-after-page-post-entry-title/).

    This is currently just some static content though. I need there to be some way for the client to add content for each page and post that this appears. I had originally thought that I could do this by showing the EXCERPT. Then I thought perhaps it would be good to use CUSTOM FIELDS. This needs to be fairly easy for the customer to change the text for each page/post. I believe it would be more efficient and intuitive for the customer to change that content on that particular page/post.

    Can someone help either with the code in the functions.php or someway to get this content on the page.

    function after_title_text() {
    if(is_page() || is_single() )
        echo '<div class="single-title">Add content after your titles but before your content here</div>';
    };
    add_action('genesis_after_post_title', 'after_title_text');

    I guess the only other way to do this would be to create a custom-styled paragraph in the content. If I can't get an Excerpt or Custom Fields to work, then I'll fall back on that method. Perhaps I'm complicating this.

    I appreciate your assistance or opinion.

    Chris

    May 18, 2013 at 1:55 am #41477
    Brad Dalton
    Participant

    Hi Chris

    This code creates a custom field named chris.

    All you need to do then is select it on all edit post/page screens using the native custom fields built into WordPress and then add a value which basically means adding the text content you want to output in the hook position, which is genesis_after_ post_title.

    Code not displaying? Grab it on Github.

    You're right that a custom field would be best but it would be even easier for your client to use a custom meta box (with a custom field) which you can position directly under the editor. That way they simply type in content and its added to the hook position included in the function above.

    I'll find a plugin that creates this meta box and get back to you soon.

    Or you could simply remove all the default custom fields and only display yours.

    Thanks for the promotion!!! haha and i also added some extra braces in the code!


    Tutorials for StudioPress Themes.

    May 18, 2013 at 8:46 am #41506
    csbeck
    Member

    Brad you are the man! I knew there just had to be a way. Thanks so much for your continued effort on this! And with the extra braces 😉 - haha.

    This works like a charm. I believe the client will be able to understand this. True though - I agree it would be better to use a custom meta box. That would be great. I have attempted custom post types on another trial project so I see the ability and the power of doing that but didn't want to go with complete custom post types since it's still basically a page or post. I can only imagine there might be some few lines of code somewhere that could add a custom meta box without going the route of custom post types. Yes, please let me know if you find anything. I will also do some searching.

    Thanks again! You've been very helpful.

    May 18, 2013 at 8:55 am #41507
    csbeck
    Member

    Looks like WP has custom meta boxes:

    http://codex.wordpress.org/Function_Reference/add_meta_box

    Looks a bit hairy and complicated. I'm sure I could copy the entire code sample and put it in my functions.php. I'll try it and see what happens. I'm just a little confused at how to grab the content from that custom meta box. i.e. how to reference it. I'll give it a go and let you know what I come up with (meaning, if it crashes me or not).  😉

     

    May 18, 2013 at 10:23 am #41511
    csbeck
    Member

    Ok, I've used that code from the WP Codex and added your function and got it to work.!

    I only made changes to a couple places.

    Your code, I added the call to the meta item:

    add_action( 'genesis_after_post_title', 'custom_field_before_content' );
    function custom_field_before_content() {
    if(is_page() || is_single() ) {
    genesis_custom_field('subtitle_text');
    }
    }

    The new code from the Codex, I changed the name of the field:

      // The actual fields for data entry
    // Use get_post_meta to retrieve an existing value from the database and use the value for the form
    $value = get_post_meta( $post->ID, 'subtitle_text', true );
    echo '<label for="myplugin_new_field">';
    _e("Please enter the custom text that follows the page title.", 'myplugin_textdomain' );
    echo '</label> ';
    echo '<input type="text" id="myplugin_new_field" name="myplugin_new_field" value="'.esc_attr($value).'" size="80" />';

    and the final line of code for what to do with it:

       // Do something with $mydata
    update_post_meta($post_ID, 'subtitle_text', $mydata);

    When I have time, I'll add a Gist or Github.

    My wishlist would be to have it use a wysiwyg editor. I'm sure a plugin or more code would do that. I'll keep my eyes open for that.

    Chris

    May 18, 2013 at 12:41 pm #41521
    csbeck
    Member

    I've created a Gist of the code that I'm using with the addition of Brad's code as well. I've put this in the bottom of my functions.php file. Hopefully it will help someone else. I will still note if I find a suitable and helpful plugin that performs this function while giving a wysiwyg editor.

    https://gist.github.com/csbeck/5605378

    Chris

    May 18, 2013 at 1:30 pm #41525
    Brad Dalton
    Participant

    Good job Chris.

    I'll modify this code and increase the height of the box as well as reposition it so its the first module under the editor.

    I know Pippin has a plugin for creating meta boxes.


    Tutorials for StudioPress Themes.

    May 18, 2013 at 2:06 pm #41529
    Brad Dalton
    Participant

    This plugin will help you customize the backend, reposition the meta boxes and hide anything you like based on user roles.

    http://wordpress.org/extend/plugins/adminimize/


    Tutorials for StudioPress Themes.

    May 31, 2013 at 3:26 pm #43414
    csbeck
    Member

    Hey Brad,

    One more item with this feature. When the code gets the content from the new field, it sanitizes it - strips off any html markup. I'd like to make it possible to add markup in that field. Can you help resolve that so any html code is viable? Or perhaps make the field have a wysiwyg editor and not have the field get sanitized?

    I ultimately want to be able to stylize the text that is there with <p> (because I'll need to indent it more than the parent div) and possibly give some of the words tags like <strong> and <em>.

    Thanks so much for your help!

    Chris

    May 31, 2013 at 10:42 pm #43430
    Brad Dalton
    Participant

    Hi Chris

    Install the Advanced custom fields plugin and create a custom met box.


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 10 posts - 1 through 10 (of 10 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble