Add an image above the WordPress post title and content

example-photo[mm-insert-title]
I had to do this recently for a client for the first time – not that difficult at all. This post serves as an example.

I used the shortcode method mentioned here.

So in functions.php I added the shortcode like this:

Then in the post I added the title where I wanted it to appear by inserting this shortcode (but remove the spaces on either side) in the main edit window.

The parameters are set in the function, but you could leave those blank and set them in the shortcode as shown in the linked post mentioned before.

Then you’ll need to add the style into your styles.css file, something like this:

Unfortunately this theme doesn’t make it easy to hide the regular title, but you can do that in CSS using body.postid .entry-title h2 { display: none; }. Or, if you add all the posts with large images before the title to a particular category you could do this:

13 comments

  1. This is a great help. One question, is it possible to do this and still retain the permalink in the title? Tried a few things without success.

  2. Hello.
    Yes – I would also like to retain the permalink but have had no success yet.
    Can you please suggest as way to do this as it would be extremely helpful.
    Thank you kindly.

  3. Hello Debbie,

    This works really well. Thank you for sharing this with us!

    Would it be possible to insert the subtitle into this shortcode? I am trying to move the title and subtitle from my post below the image. Would I need to create a new shortcode or can it be inserted into this one? I tried making my own shortcode for subtitle but it isn’t working.

    Your help is greatly appreciated! Thank you!

    Antonella

  4. Hi Debbie,

    Thanks for your help. I also found and tried the link you gave me but all it does is add these words: “Title:default titleSubtitle:default subtitle.”

    By the way, I just realized that the sub-title is a custom field I added (sorry I forgot). So I guess my questions is how can I create a shortcode of a custom field?

    I’m searching online but the only results I get is how to use shortcodes in custum fields, not how to create a shortcode of a custom field.

    I understand you are busy. I would do this myself if I knew how to make shortcodes.

    Thank you for your help!

    Antonella

  5. Okay, I was able to figure it out using the method proved from the linkyou gave me.

    – First I made a custom field titled ‘sub-title’.

    – Then I inserted this code into functions.php:

    `function shortcodefunction() {
    global $post;
    return get_post_meta($post->ID, ‘sub-title’, true);
    }
    add_shortcode(‘sub-title-function’, ‘shortcodefunction’);`

    – Then I insert [sub-title-function] above the text in my post.

    This turns a custom-field into a shortcode which can now be placed anywhere in the content of my post.

    Thanks for all your help Debbie!!

Leave a Reply

Your email address will not be published. Required fields are marked *