Add excerpt after page / post entry-title

Community Forums Forums Design Tips and Tricks Add excerpt after page / post entry-title

This topic is: not resolved

This topic contains 6 replies, has 2 voices, and was last updated by  braddalton 2 years, 6 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #41302


    I’m using Agency and I would like to show some text below the page’s/post’s title – only on their individual page/post.

    I was thinking I could put the excerpt there or some custom field text by creating a new single-page and single-post template or by using a hook. The only other way I can think of for doing what I want to do, is to create a styled paragraph. Which I can do. But I’m wondering if doing it with the excerpt and hook or template might be better. Has anyone done something like this or at least can someone make some suggestion?

    Development site:

    Thanks much! Chris


    Try this:

    Code not displaying? Grab it on Github.



    This is great Brad. I’ll give it a try.

    With this hook in there, how would I dynamically pull the excerpt or custom field content into this section?

    Would I?:

    • Create a custom field on the page (I could call the custom field “thispage_excerpt”)
    • Add content (value)
    • Then in your code put something like:
      • echo ‘<div class=”single-title”><?php the_meta(); ?></div>';


    Your code needed another set of curly brackets to encase the statement within the if statement. Then the text showed up just like I wanted!

    But now I want to add some dynamic text there so different pages could show different text and I’d like to modify that from the page.

    OK, so here’s the code that I put in my functions.php:

    function after_title_text() {
    if(is_page() ) {
    echo ‘<div class=”thispage_excerpt”><?php the_meta(); ?></div>';
    add_action(‘genesis_after_post_title’, ‘after_title_text’);

    I’ve also added a custom field on my test page:

    Key: Page ExcerptValue: This is my excerpt.

    When I test the page out, the div exists on the page but the content doesn’t. I’m afraid that I’m doing custom fields incorrectly. Can regular pages not have custom fields? Can you give any further advice?

    Thanks, Chris



    Hi @csbeck

    I tested my code before I embedded it here and it works.

    I also tested it again now and it stills works.

    I am fully aware it doesn’t include the braces which I normally add to PHP code when hooking in widgets, but it doesn’t need the braces when echoing in basic text.

    1. Firstly, when pasting code in this forum, please use the PHP shortcodes. You can learn more in FAQ No.5

    2. When copying PHP code from a embedded snippet, use the view raw link and paste it at the end of your child themes functions.php file using a text editor like Notepad++.

    If you use the WordPress theme editor, the apostrophes can change and cause errors.

    I’d suggest you post your second question as a new thread.

    Personally, I have never used custom fields and prefer pure PHP code as its cleaner and easier to manage. Why complicate things which result in less efficiency?

    I’ll try to find you a solution using PHP without the custom fields.

    Thank you.



    Hi Brad,

    Thanks so much for both your FAQ suggestion and looking into a solution. I will do better at posting code now.

    As for your code, your code does work, I was incorrect and I apologize. But it didn’t work on the PAGE where I was looking because a single PAGE is not identified as “single”. So your code didn’t affect my test PAGE. Now I went to a post and there is your text. So thanks for getting that to me. I hope you don’t take offense at my responses due to my ignorance and less experience of PHP – which I’m attempting to improve upon – I’m more of a designer.

    If anyone cares, I’ve modified the code to be this so that it will appear on both PAGES and POSTS:

    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’);

    So thanks again and your searching for an alternative is very much appreciated.

    Though I don’t understand why I would need to create a separate thread; I still feel the solution to this (be it PHP, shortcodes, or custom fields) would be associated to my original question, I will create a separate thread.

    Thanks! Chris



    Thanks for the code Chris and explanation about the different conditional tags which effect pages and posts.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.