Support » Fixing WordPress » Main body only PHP tag

  • Hey folks,

    Relatively new to WP, and I’m sorting out the og tags for sharing content via various websites, what’s been troubling me recently is the

    og:description tag, what I would like it to display is the most recent post title, and then the content. However it concatenates the two together so on a facebook share, instead of appearing as
    ‘Blog Title. Start of Blog Post’
    it appears as ‘Blog TitleStart of Blog Post’

    I’ve managed to identify the tag to grab just the blog title, in <?php the_title(); ?>" however when I’ve been looking for a tag that solely picks up the content of the blog post without the title, I’ve had no luck, I’ve tried the_post()and the_content()

    Any help would be appreciated

Viewing 1 replies (of 1 total)
  • You mention both blog title and post title, so I’m not clear on which you want.

    For the blog title, use:

    <?php bloginfo('name'); ?>

    However, for the post title, use:

    <?php the_title(); ?>

    For the content, use:

    <?php the_content(); ?>

    This returns the body of the post – but this can be lengthy. You may actually want the excerpt instead, which is either the defined excerpt or the first 55 characters:

    <?php the_excerpt(); ?>

    Now you just need to string them together. One option would actually be to put the blog title and post title together, like so:

    <?php bloginfo('name').': '.the_title(); ?>

    This gives you something like this:

    Blog Title: Post Title

    You could of course change that separator – I just included it for illustration. The important part is that when you put the two next to each other, or even if you do one, then later do another one, they print the information with no separation. By adding concatenating the data, with a separator, you get what you want.

    You could also do a title with content:

    <?php bloginfo('name').': '.the_content(); ?>

    And so on. Alter as needed.

Viewing 1 replies (of 1 total)
  • The topic ‘Main body only PHP tag’ is closed to new replies.