Support » Themes and Templates » Add title inside the_content

  • ghaib


    In WP, the_title is always displayed outside of the the_content, but is it possible to display it inside, so that the title is part of the content, and can be aligned likewise?

    For example, take a look at this site — notice its titles inside the white box, how the title and the content is aligned to the left, while an images aligned to the right.

    Is this possible in WP?


Viewing 7 replies - 1 through 7 (of 7 total)
  • JarretC


    Yes it is possible in WordPress, however that all depends on how the theme is coded of course.

    Well, the theme is coded like any other WP theme.

    That really doesn’t help much as there are thousands of themes available nowadays and almost each one is coded slightly differently. Do you have a live website so I can take a look at the code or do you have a theme in mind that you want to use?



    Forum Moderator

    even in your example link, the title is outside the content; only the image is shown to the right of the title and content, which could be done using the_post_thumbnail() in its own div, for instance.

    unless you can provide the name of the theme that you are planning to use, and/or a link to your site, nobody will be able to help in any substantial way.

    general, there are possible ways to ‘push’ the title into the content.
    for instance, you could replace:

    <h2><?php the_title(); ?></h2>
    <?php the_content(); ?>

    with something like:
    <?php $text = '<h2>' . the_title('','',false) . '</h2>' . get_the_content(); echo apply_filters('the_content', $text); ?>

    i am however not sure how this would help you to achieve a layout as in your example link.

    @alchymyth I applied your code, it seems to be working.

    In essence, what I want is the title (h2) to be included in the same <div> as the content, usually it’s:

    <h2>Test title</h2>
    <div class="content">The content</div>

    What I’d like to achieve is something like this:

    <div class="content">
    <h2>Test title</h2>
    The content</div>

    While your code works, what if I want to wrap the title in additional divs, and have it be a link as well?



    Forum Moderator

    what if I want to wrap the title in additional divs, and have it be a link as well?

    should be no problem – simply try it.

    I tried, I’m getting this error:

    syntax error, unexpected T_LNUMBER

    I think it’s because I also include the comment code <?php comments_popup_link('0', '1 ', '% '); ?> right after the title (in a div).

    Any ways of fixing this? (I’m not a php wiz 🙂 )


Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Add title inside the_content’ is closed to new replies.