Free Tips & Tricks!

Join the others who've found my articles helpful! Get free goodness delivered to your inbox each time I share something new.

p.s. I'd gnaw my arm off before selling your email address.

Minimum Theme: How to Lay Text Over an Image

Have you seen the new Pretty Pictures Theme from StudioPress? It’s stunningly simple and right in line with the other clean, minimal themes created by Brian Gardner this year.

The text overlay on the large featured image is one of my favorite design elements of Pretty Pictures. The theme layout cleverly takes advantage of  Genesis custom header support to pull this off. You just go to Appearance > Header to upload your background image and then tootle on over to Appearance > Widgets > Header Right to add your overlay text.

Pretty Pictures Featured Image

But if what if you’re not using Pretty Pictures and want to add the text overlay effect to a different StudioPress Theme?

A couple of readers asked this question after I posted last week about how to add a featured slider to the Minimum Theme. This post will show you one way to go about it.

Text Overlay on the Minimum Theme

I’m going to tackle this simply. The large featured image that appears on the Minimum home page is hard-coded. We’re going to use a widget area plus a little CSS to position our text over the image.

Create a New Widget Area

We need to register a new widget area to house the text we’re going to show over the featured image. From your WordPress admin dashboard, go to Appearance > Editor and open up functions.php.

Any time you’re working directly in the functions.php file, you risk making a mistake that’ll take your site DOWN. Be ready to access your site via FTP to rescue any mis-placed semi-colons. You have been warned.

Add this bit of code, preferably toward the bottom of the file with other widgets being registered:

Add the Widget Area to the Home Page

If you were to go check out Appearance > Widgets, you’d see that your new widget area exists. Now we need to specify where it shows up.

We’re still rooting around in functions.php, so find the featured image section (around line 66 in a default install of the Minimum Theme).

Change this:

function minimum_featured_image() {
    if ( is_home() ) {
        echo '<div id="featured-image"><img src="'. get_stylesheet_directory_uri() . '/images/sample.jpg" /></div>';
    }

To this:

function minimum_featured_image() {
    if ( is_home() ) {
	echo '<div id="featured-image"><img src="yourimage.jpg" class="underlay" />'; // add underlay class
	genesis_widget_area( 'my-widget', array( 'before' => '<div class="my-text">', ) );  //replace widget ID if needed
	echo '</div></div>';
    }

Add some CSS Styling

Open up your stylesheet and locate the style for the #featured-image. This is going to be the container that holds our featured image as well as our overlay text. Change it out to this:

#featured-image {
     height: 600px; /* Set this to your actual image height */
     margin: 0 auto;
     position: relative;
     width: 1600px; /* Set this to your actual image width */
     z-index: 0;
}

Next we need to style the actual featured img. In the previous step we added a class called underlay, so let’s add some style for that:

.underlay {
     position: absolute;
     z-index: -999998;
}

The z-index property works within positioned elements to stack, or layer, items. Giving a ridiculously large z-index to the image basically ensures it’ll display BELOW our text. You can read more here about how z-index works.

Last, but not least, we need to style our widget area that’s going to hold our overlay text. Your style will vary based on your design and whether you want the text to fall on the left, right, or center of your image. Here’s an example if I wanted my text to be on the left side.

.my-text {
    overflow: hidden;
    padding: 10%;
    width: 30%;
}

.my-text p, .my-text h4 {
    color: black;
    margin-bottom: 15px;
    text-shadow: 1px 1px #CCCCCC;
}
I haven’t tested out these additions for mobile responsiveness. You may need to tinker with the CSS.

After testing the above code, here’s what I came up with for the home page on the Minimum Theme:

Text Overlay on Featured Image of Minimum Theme

Try it out and let me know how it works for you!

Comments

  1. Sweet! Great post; thanks for the tip and great explanation. Cheers, Steve & Sally Wharton, Seattle

  2. Hi Carrie
    I think that from an SEO point of view all text should be real text and not text that is part of an image.
    The GoogleBot can only read real text, it can’t read image text.

    The Pretty Pictures theme solved the problem, but sadly no solution for Minimum 2.0… until the Genesis coding fairy appeared just before the New Year and sprinkled coding dust over the functions.php file.

    Thanks for coming up with what my old maths teacher would call “an elegant solution” and a solution that most genesis users would be able to attempt.

    Having a solution like this means that you can change the text, restyle the text and reposition it.
    Lots of Minimum 2.0 users will absolutely love this.

    BTW – I have got to have a pair of those boots, just got to!

    Happy 2013 to you and yours Carrie.

    • Keith, you are spot on regarding SEO benefits to using actual text. I think the text also renders cleaner as opposed to any pixelation that might happen when saving to jpg or png.

      Can’t wait to see this in action on your site. Let me know if you run into any problems!

      As for those boots, Texas is crawling with them. You make it over to this side of the pond and I’ll take you shopping myself. ;)

  3. Really great tutorial, here is what I had to do to get this tor work.

    Using this code allows you to keep the same “sample.jpg” structure of the original. I also changed the names of the widget and the class. I called them “text-overlay” and “widget-text-overlay”.

    function minimum_featured_image() {
    if ( is_home() ) {
    echo ”; // add underlay class
    genesis_widget_area( ‘text-overlay’, array( ‘before’ => ”, ) ); //replace widget ID if needed
    echo ”;
    }

    Here is how I registered the widget:

    /** Register widget area */
    genesis_register_sidebar( array(
    ‘id’ => ‘text-overlay’,
    ‘name’ => __( ‘Text Overlay Widget’, ‘theme-slug’ ),
    ‘description’ => __( ‘Places text over homepage image’, ‘theme-slug’ ),
    ) );

    And then of course changed the CSS a bit to this:

    .widget-text-overlay {
    overflow: hidden;
    padding: 10%;
    width: 30%;
    }

    .widget-text-overlay p, .my-text h4 {
    color: black;
    margin-bottom: 15px;
    text-shadow: 1px 1px #CCCCCC;
    }

    Works great though, thanks for the write-up, made my life much easier.

  4. I echo the “SEO likes this” comment, it’s definitely better to have the text be “text” if at all possible. (I was noting this earlier this morning while reading someone else’s blog, and contemplating writing a plugin to reposition caption text on top of the image. Oh well…)

    I did have to chuckle, though – in all the above images dealing with real text on photos, the text is not real text! lol

  5. Hi Carrie, I am trying to add an opague background around the text widget and for some reason it’s putting it around the text and not the text widget itself. How can I add an opaque background to the widget area? Thanks in advance.

  6. Great post!

    Ok, full disclosure here: Im a bit of a noob.

    However, I have changed all the code and set everything up as described here but Im obviously missing something – How (or where) are you actually putting the text?

    I tried just dropping a Text area into ‘My Widget’ but that didnt seem to work. What am I missing here? I feel like its something obvious and elementary…(See Noob).

    Thanks in advance for the help!

    • Hey Josh,
      Glad you found it helpful. Gotta check with you – did you actually type text into the text widget? If it’s a empty widget, nothing will show. :) Provide a link to your site and I’ll see if I can help troubleshoot!

      Carrie

      • Carrie –
        Thanks for the reply! I did put text in there but I dont see anything. I dont even see the div in my browser’s inspector. The site is under massive construction and Im just not sure what Ive done wrong.
        http://lumetechnologies.com/

        • Hmmm you are right! That’s what I was going to look for, too. Can you post the entire code chunk for function minimum_featured_image() ?

          • joshrhine says:

            Sure thing! Here’s what I have in my functions.php file:

            function minimum_featured_image() {
            if ( is_home() ) {
            echo ”;
            genesis_widget_area( ‘my-widget’, array( ‘before’ => ”, ) );
            echo ”;
            }
            elseif ( is_singular( array( ‘post’, ‘page’ ) ) && has_post_thumbnail() ){
            echo ”;
            echo get_the_post_thumbnail($thumbnail->ID, ‘header’);
            echo ”;
            }
            }

          • Ah! Try this:

            if ( is_home() ) {
            echo ‘

            ‘;
            }

            Just need to throw those divs in there and you should be good.

          • joshrhine says:

            Awesome Carrie! I’ll try this tonight – thanks for the help!

  7. Your tutorial worked perfectly for me, absolute beginner.
    My next step is to adapt this tuto to add an optin-form over the featured image of my home page.
    Thanks a lot Carrie !

  8. Just a quick note. This is a good tutorial, but unfortunately, if you change anything else in the way Minimum was made, you’ll likely break other things in the process.

    For example… While it works fine for the homepage, it also means that all featured images in the site have to be the same size as the homepage image. In the site I’m working on, only the homepage image is 1600px wide. All the post featured images are 740px (content width). Secondly, no it doesn’t play well as mobile responsive. Additionally, the guys at Studiopress had created a plugin for Minimum to allow the use a thumbnail featured image and a large banner image. Given, I couldn’t get this code to work well on my site, I’m not going to take it as far is to see how it would play with that plugin.

    Thanks for the tutorial and for providing the code. Unfortunately, for it to work for some, they would also need to be CSS and PHP ninjas to be able to customize it to work for their sites. I had to remove it and go back to have it was. Thanks nonetheless. -Danny

    • Hi Danny,
      The code in the tutorial won’t break anything in a standard installation of Minimum, but you’re right – the tutorial does require some working knowledge of CSS and PHP – especially if you’ve made other modifications to your theme. You can use conditional statements and declare a second ‘featured image’ size to handle featured images on those inner pages. I’ve played with the GMIE plugin you mention and it’s fantastic.

      Keep playing and have fun!
      Carrie

  9. Hi Carrie,

    Fantabulous aticle! It is so very helpful to me as I do not have training in coding but I am editing my wordpress site on my own so I am learning as I go. I am using the Minimum theme and I just needed to ask if I want to change the huge featured image size on my home page to a smaller height do I simply add this code into the stylesheet and adapt it to the size I want? Or should I remove the irrelevant lines, if any?

    #featured-image {
    height: 600px; /* Set this to your actual image height */
    margin: 0 auto;
    position: relative;
    width: 1600px; /* Set this to your actual image width */
    z-index: 0;
    }

    Cheers,
    Su

  10. So often I’m looking for info/help on stuff and run across sites that are filled with “corrections” in the comment sections or the advice is insanely complex and would require a client to be familiar with something other than WordPress visual editor. This site is clearly not one of those – to echo the first commenter, I think quite possibly you are the Code Fairy Godmother! I am one of those people who never signs up for newsletters, etc. as a matter of policy/stubbornness, whatever. I’ve never done it – until now. For the first time ever, I’m actually going to use an optin form – yours! I consider myself intermediate, and there’s not a lot of stuff “out there” for a lot of us who aren’t up to our elbows in php all day, but are definitely not beginners, either. Thanks so much for so much great information! I just realized how spammy this comment looks, but I mean it sincerely, lol :)

  11. I followed your instructions, but seem to have lost the picture on the home page. Where do I find it and how do I insert the picture of my choice. Sorry if this is a sophomoric question.

  12. Hi Carrie,

    For some reason, my text continues to appear below my image on my home page.

    Do you know why this is the case?

  13. brenners78 says:

    Thank you so much, Fairy Codemother! ;) I love it!!

    I managed to jack up the entire site by not commenting out the old featured image function before adding the new. But once that was all fixed and I got it all lined up right, there’s no way I would remove the overlay. I just love it that much.

    Wondering if adding a translucent white background (kinda see through) to the overlay is easy enough or maybe I should just add it to the featured image photo in Photoshop.

    • That’s a tricky one. If you add it to the widget div, the text will pick up the opacity, too. I think if you get one extra div in behind the text you could target with an opaque background. Never do with Photoshop what you can do with a little CSS. :)

  14. Hi Carrie! Loving your website. Lots of useful information!

    I’m thinking of purchasing the minimum theme from studiopress but I’d really love for the top navigation menu to remain sticky as you scroll down the page.. Do you know if this is easy to do?

    I’d also like the sticky menu to fade out when it’s not being hovered over. Basically, I want it to look like this! http://nikkijumper.com

    Let me know if you think this is do-able. Thank you! :)

Trackbacks

  1. [...] shown you a couple of nifty Minimum Theme customizations in the past, like how to lay text over image on the home page or swap out that image for a [...]