This post is a collection of tips and tricks for getting the most out of the powerful Divi Theme by Elegant Themes. If you've installed the Divi theme and need some help adjusting the appearance to suit your needs, let me know in them comments and I'll do my best to help you out.
About the Divi Theme by Elegant Themes
The Divi WordPress Theme is a slick, modern theme from Elegant Themes. It has recently become one of the top 10 most used WordPress themes, thanks to its impressive flexibility and ease-of-use.
Chances are that if you've made it to this post theme you are already using the theme and are looking to squeeze every last ounce of awesome out of it.
But if you still shopping around for a new WordPress theme you may want to take a look at the Divi Theme (or one of the other 87 themes by Elegant Themes).
Removing Image Backgrounds
When you add captioned images into your posts, they are given a grey background and border. If you want to remove this, add the following to the end of the theme's style.css file:
.wp-caption { background-color:white; border:0; }
Adjusting Image Sizes
If you want to adjust the size of the images embedded in your posts, add something like this to the end of your style.css file:
.wp-caption { width: 400px !important; } .wp-caption img { width: 390px !important }
Note: set the width to suit your needs and keep a 10px difference between widths in the two CSS rules.
Hiding the Related Posts Widget
To hide the related posts widget, add the following to the end of your theme's style.css file:
#recent-posts-2 { display:none; }
Hide the Divi Header When You Scroll Down
By default, the main Divi header will start off large, then shrink to a smaller version when you scroll down.
The best way to prevent the header from hovering over the content when you scroll down via the ePanel. There is a "Fixed Navigation Bar" option under "General Settings". Set this to disabled and the header will no longer shrink and hover over the content.
If you need a CSS solution, you can hide it instead by adding this the end of the Divi theme’s style.css file:
.et-fixed-header { display:none; }
With this, when you scroll down the header will disappear instead of shrinking.
Hide the Divi Header
You can completely hide the main Divi header bar using the following CSS:
#main-header { display:none; } #page-container { padding-top:0px !important }
It hides the header, then moves the rest of the page up into the space the header occupied.
Apply a Style to a Single Text Module
To apply a style to a single text module, we can use a CSS rule like this:
.post-57 /* apply to page / post with ID 57 */ .et_pb_section:nth-of-type(1) /* apply the the first page builder section */ .et_pb_row:nth-of-type(1) /* apply to the first row of the section */ .et_pb_column:nth-of-type(2) /* apply to the second column of the row */ .et_pb_text:nth-of-type(2) /* apply to the second text module in the column */ { font-size: 14pt; }
This looks quite complicated, but it's actually fairly simple.
The page builder lays out pages in sections. Each section is then split into a number of rows, and each row into a number of columns. Each column contains a number of modules, some of which may be text modules (which have the .et_pb_text class). The rule above uses the nth-of-type operator to navigate this structure, picking the correct section, row, column and text module within the required page.
Finally, we can set the style attributes (such as the font-size) for the targeted text module.
Hide the Divi Logo
You can remove the Divi logo, without needing to remove the header or add your own logo, by adding the following CSS:
#logo { display:none !important; }
Add a Widget Area to the Divi Header
The following code will create a new widget area named "Header" and then (using jQuery) add it below the links on the right of the Divi header (see here if you also want to remove the header links). The code below should be added to your functions.php file, or better yet, to a child theme.
// Create the new widget area function myprefix_widget_area() { register_sidebar(array( 'name' => 'Header', 'id' => 'myprefix-widget-area', 'before_widget' => '<div id="%1$s" class="et_pb_widget %2$s">', 'after_widget' => '</div> <!-- end .et_pb_widget -->', 'before_title' => '<h4 class="widgettitle">', 'after_title' => '</h4>', )); } add_action('widgets_init', 'myprefix_widget_area'); // Create the widget area and then move into place function myprefix_footer() { ?> <div id="myprefix-widget-area-wrap"> <?php dynamic_sidebar('myprefix-widget-area'); ?> </div> <script> jQuery(function($){ $("#et-top-navigation").after($("#myprefix-widget-area-wrap")); $("#myprefix-widget-area-wrap").show(); }); </script> <?php } add_action('wp_footer', 'myprefix_footer'); // Adjust the layout so that it fits into the header better function myprefix_css() { ?> <style> #myprefix-widget-area-wrap { display:none; float:right; max-width: 500px; clear:right } #myprefix-widget-area-wrap .et_pb_widget { margin-right:0px } #myprefix-widget-area-wrap .et_pb_widget:last-child { margin-bottom: 18px; } .et-fixed-header #myprefix-widget-area-wrap .et_pb_widget:last-child { margin-bottom: 10px; } @media only screen and ( max-width: 980px ) { #myprefix-widget-area-wrap .et_pb_widget:last-child { margin-bottom: 0px; } } @media only screen and ( max-width: 768px ) { #myprefix-widget-area-wrap .et_pb_widget:first-child { margin-top: 18px; } } </style> <?php } add_action('wp_head', 'myprefix_css');
Make Gallery Images Show Caption instead of the Title
To show a caption instead of the title when viewing the full size image from a gallery, you can change this bit of code (located around line 3625 of the Divi functions.php file):
$image_output = sprintf( '<a href="%1$s" title="%2$s" rel="nofollow"> <img src="%3$s" alt="%2$s" /><span class="et_overlay"></span> </a>', esc_attr( $full_src ), esc_attr( $attachment->post_title ), esc_attr( $thumb_src ) );
To:
$image_output = sprintf( '<a href="%1$s" title="%2$s" rel="nofollow"> <img src="%3$s" alt="%2$s" /><span class="et_overlay"></span> </a>', esc_attr( $full_src ), esc_attr( $attachment->post_excerpt ), esc_attr( $thumb_src ) );
Note that all I've done is change the "post_title" part to "post_excerpt".
Add a Full-Width image Above the Header
You can make Divi show a full-width image above the navigation bar by adding the following to the Divi functions.php file, or to a child theme:
// load jQuery wp_enqueue_script('jquery'); // hook the widget area into the footer, then move into place in the header function myprefix_add_header_img() { ?> <div style="display:none"> <img id="myprefix-page-start-img" src="http://www.mysite.com/my-image-url.jpg"/> </div> <script>jQuery("#myprefix-page-start-img").prependTo(jQuery("body"));</script> <?php } add_action('wp_footer', 'myprefix_add_header_img'); // CSS to display the image and header correctly function myprefix_css() { ?> <style> /* Change header to float correctly wherever it is in the page */ @media only screen and ( min-width:981px ) { #main-header { position:relative !important; top:0px !important; } #main-header.et-fixed-header { position:fixed !important; margin-bottom:0px; top:0px !important; } body.admin-bar #main-header.et-fixed-header { top:32px !important; } #page-container { overflow:hidden; } } /* Style the image for full screen layouts */ @media only screen and ( min-width:981px ) { #myprefix-page-start-img { margin-bottom:-80px; width:100%;} } /* Style the image for box layout */ @media only screen and (min-width: 1200px) { .et_boxed_layout #myprefix-page-start-img { width:1200px; -moz-box-shadow: 0 0 10px 0 rgba(0,0,0,0.2); -webkit-box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.2); box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.2); display:block !important; margin-left:auto; margin-right:auto; } } /* Hide the image on smaller screens */ @media only screen and ( max-width:980px ) { #myprefix-page-start-img { display:none; } } </style> <?php } add_action('wp_head', 'myprefix_css');
The only thing you should need to change is the image url in the myprefix_add_header_img function.
Changing the Height of the Divi Slider
The Divi Theme comes with a slider module to let you display a gallery of images. It has a fixed height, but this can easily be changed by adding a bit of CSS to the theme, e.g.:
/* Set the slider height */ @media only screen and (min-width:981px) { .et_pb_slider, .et_pb_slider .et_pb_container { height: 425px; } .et_pb_slider, .et_pb_slider .et_pb_slide { max-height: 425px; } .et_pb_slider .et_pb_slide_description { position: relative; top: 25%; padding-top: 0 !important; padding-bottom:0 !important; height:auto !important; } }
Note that this will change the height of the Divi slider on all pages with a slider – just change the two occurrences of "425px" with your desired height. The height change is only applied on desktops; on mobiles it defaults to the standard Divi height.
If you want to affect just one slider, you can add a CSS class in the slider module options, and then replace the 5 occurrences of "et_pb_slider" in the above with the name you choose for your CSS class.
I've used "top: 25%" to display the slide titles 1/4 of the way down the slide (so that all slide titles appear in the same place). Increase this if you want the slide titles and descriptions to be moved lower down the slide.
Changing the Sidebar Background Color
We can start by setting our desired background color on the "sidebar" element, like so:
#sidebar { background-color: #fafafa; }
For a light-grey background. Or for a semi-opaque black background:
#sidebar { background-color: rgb(0,0,0,0.5); }
You'll notice however, if you do this, that it doesn't look particularly good. The sidebar element tightly surrounds the content meaning that the contents of the sidebar are right up against the edge of the sidebar.
To fix this we can adjust the padding and margins. We need to specify several sets of padding and margins to handle the various screen sizes supported by Divi. Here is an example set of padding and margin rules which I think gives a nicer result:
#sidebar { background-color: #fafafa; } @media only screen and (min-width: 1100px) { /* full-size screens */ .et_left_sidebar #sidebar { /*left*/ padding:70px 0 200px 30px; margin:-70px 0 0 -30px; } .et_right_sidebar #sidebar { /*right*/ padding:70px 30px 200px 0px; margin:-70px -30px 0 0; } } @media only screen and (min-width: 981px) { /* medium-size displays */ #sidebar { padding:70px 30px 200px 30px; margin:-70px -30px 0 -30px; } } @media only screen and (max-width: 981px) { /* mobiles, etc */ #sidebar { padding:30px } }
This code works for both left and right sidebars.
Removing the Divi Sidebar Dividing Line
To remove the thin dividing line between the page content and the sidebar, add the following CSS:
.container::before { display:none; } .et_pb_widget_area_right { border-left:0; }
Fix the Header Bar Links Vertical Alignment
If you change the logo height you may find that links on the right of the header bar are no longer vertically centered. You should be able to fix this by using the following CSS to vertically center the links and search icon in the header area:
@media only screen and ( min-width: 981px ) { /* Vertically center the top navigation */ #et-top-navigation { display:table-cell; vertical-align: middle; float:none !important;} .container { display:table; } /* Right align the contents of the top navigation area */ #et-top-navigation { text-align:right; } #et-top-navigation > * { text-align:left; } #top-menu-nav, #et_top_search { float:none !important; display:inline-block !important} #et_top_search { vertical-align: top !important; margin-top:3px } }
Adding a Semi-Transparent Background Image to the Header
If you'd like to add a semi-transparent background image to the Divi Header, you can do so by adding the following CSS to your theme:
#main-header::after { content: ""; background-image: url('myimage.png'); background-size:cover; opacity: 0.5; top: 0; left: 0; bottom: 0; right: 0; position: absolute; z-index: -1; }
Just replace 'myimage.png' with the URL of your desired background image.
Changing the Sidebar Width
The Divi sidebar is quite narrow, and increasing its width is not particularly easy. But the following code will allow you to increase (or decrease) the divi sidebar width. In this example, I'm setting the width to 300px, but you can replace it with your choice of width.
@media only screen and ( min-width: 1100px ) { .et_right_sidebar #sidebar .et_pb_widget { margin-right:30px !important; } .et_left_sidebar #sidebar .et_pb_widget { margin-left:30px !important; } .et_right_sidebar #left-area, .et_left_sidebar #left-area { width:720px !important; /* 1020 - width */ } .et_right_sidebar #main-content .container:before { right:300px !important; /* width */ } .et_left_sidebar #main-content .container:before { left:300px !important; /* width */ } .et_right_sidebar #sidebar, .et_left_sidebar #sidebar { width:300px !important; /* width */ } }
Other than replacing each instance of 300px with your desired width, you need to replace the 720px with 1020 minus your desired width.
This should set the sidebar (either right or left sidebar) to a width of 300px, on full screens. On smaller screens, the default Divi sidebar width is used.
Changing the Header Phone Number and Email Font Sizes
Divi lets you to set a phone number and email address to be shown at the top of the header. You can adjust the font size of these items with the following CSS:
#et-info-phone { font-size:130% } /* phone number */ #et-info-email { font-size:130% } /* email address */ #et-info { font-size:130% } /* both at once */
Note that the default font-size is 100% so anything bigger than this will increase the font size and anything smaller will decrease it.
Full-Width Featured Images
First, we can put the image into position with the following CSS:
body.single article.has-post-thumbnail > img:nth-of-type(1) { position:absolute; left:0; top:0; }
Now we need to move the post title and content, and the sidebar, below the image. We can do this by setting a top-margin on the content-area element, which is equal to the height of the featured image. It is easiest to do it using jQuery, which lets us easily adjust the margin as the image height changes between posts and on browser resizes. Here's the jQuery code, which can be added into footer.php:
<script> jQuery(function($){ var featured = $('body.single article.has-post-thumbnail img:nth-of-type(1)'); var contentarea = $('#content-area'); if (featured.length) { adjust_margin(); $(window).resize(function(){ adjust_margin(); }); } function adjust_margin() { contentarea.css('margin-top', featured.height()); } }); </script>
Swap the Slide Image and Slide Description Positions
If you'd like to have your slide images on the right instead of the left, you can use the following CSS:
.et_pb_slide_description { float:left !important; padding-left:100px !important } .et_pb_slide_image { right:100px; }
To make the change to just a single slide (e.g. the first one) on a particular slider, give the slider a CSS class, such as "myslider" and use:
.myslider .et_pb_slide:nth-of-type(1) .et_pb_slide_description { float:left !important; padding-left:100px !important } .myslider .et_pb_slide:nth-of-type(1) .et_pb_slide_image { right:100px; }
Prevent Image Gallery Thumbnail Stretching
The Divi Theme gallery module has a grid view which shows thumbnails of the images in the gallery. Sometimes the thumbnails will appear distorted, as small images are stretched to fill the thumbnail area. To prevent the image stretching, we can use the following CSS:
.et_pb_gallery_image img { min-width:0 !important; min-height:0 !important; position: relative; left: 50%; top: 50%; transform: translateY(-50%) translateX(-50%); }
This removes the minimum height and width setting which was causing the stretching, and centers the image in the thumbnail area.
Remove the Header Bar Bottom Border
If you'd like to remove the border from the bottom of the header bar, you can do the following:
#main-header{ -webkit-box-shadow:none !important; -moz-box-shadow:none !important; box-shadow:none !important; }
Changing the Look of Post Titles
To change the style of the post titles in Divi, you use CSS like the following:
.single h1 { font-family: Courier; font-size: 30pt; color: green; border-bottom: 1px solid #ddd; }
This example change the post title font to Courier, makes the font size bigger, makes the title green, and adds a thin grey line under it (by adding a bottom border).
Adding Dividing Lines Between Widgets
To add a dividing line between the individual widgets in the sidebar, you can add this CSS:
#sidebar .et_pb_widget { border-bottom: 1px solid #ddd; padding-bottom: 20px; margin-bottom: 20px; } #sidebar .et_pb_widget:last-of-type { border-bottom:0; }
The first part adds a bottom border to each widget (the same color as the vertical sidebar divider), and positions it mid-way between successive widgets. The second part removes the bottom border on the final widget.
How do I add a text box color to my sidebar?
And where do I paste the CSS? I am very new to CSS and divi
Hi ling,
Sorry, could I get you to explain a bit more what it is you're trying to do? I'm not completely sure what it is you're trying to achieve. Are you looking to add a colored box with some text in it, or is it an actual HTML textbox element that you want to color, or something else? If you've got an link to the page with the text box you want to color, that would help a lot.
I've written up a post about adding text to Divi, which should answer that part of your question at least!
I have found a website example that shows what i'm trying to achieve.
http://www.thesteakhouse.com.sg/index.php/main/index2
Basically, i have a left sidebar and I want to have a background color to it, like the one in the example.
Is it possible to do so?
I'm sorry for not explaining clearly.
Okay, I get it now. Thanks for that :)
I've added a section above describing how to set the sidebar background color. You might also want to look at the bit about removing the dividing line.
Hope that helps!
Hey Dan,
I was wondering if there's a way to change the '#page-container{ padding-top:xx}' when scaled to the mobile view, differently than on normal view.
But also, I would like to set the padding-top to be different on the homepage, versus the inside pages.
So in total there would be four different variables to the padding-top, of #page-container.
I want to do this because I'm pushing a header image under a transplucent version of the top navigation, but it doesn't look right on the mobile views, since it pushes h1 title text up into the navigation bar.
If you can help me you're a life saver!
Thank you,
Abe
Hi Abe,
I think this will do what you need:
I've used the "home", "single" and "page" classes of the body element to target the homepage, posts and pages respectively.
I've used a media query to trigger mobile-specific padding when the page width falls below 981px (you may want to play around with the width at which your mobile-specific padding kicks in, but 981px is the point at which Divi stops using a floating header, so hopefully it is right for you).
Finally, I've added !important to all the padding rules to make sure the browser uses our rules instead of the default top-padding set by Divi which would otherwise take precedence (as it is set using inline CSS).
Hope that helps!
Dan, you rock!
A member of the elegant press actually gave me a worse solution than yours. This is perfect, exactly what is needed. Flawless!
I owe you a drink!
-Abe
Ha ha! Glad it's what you wanted! I'm a dark ale man… :)
A stout, or a lager, maybe a Guinness?
I seem to have the issue mostly sorted out, but I notice there's a middle zone that Divi is messing with as well. If you slowly scroll the width of the theme, you'll see that somewhere between 600-800 pixels it messes up the height again and the background image looks funky.
On an off-note I'm trying to set the background image of the main mobile menu, the css is currently commented out because if on, the translucency stops displaying properly and so do some of the h2's lower on the page… (this is a much lower priority atm than the previous task)
Thank you brother!
Abe
Ha ha! It's all good to me!
Okay, I can see where it's messing up. You can use another media query to target this zone. So your code will end up looking like:
Where the dots are replaced by the padding rules as per my previous comment. Note that I've also reduced the max-width for the mobile part.
The widths are a bit higher than you noticed, but I think I've got them correct – they match up with Divi's main breakpoints. Anyway, give it a shot and adjust if needed.
I'll take a look at the mobile background image separately next chance I have :)
I've added a section on setting a semi-transparent background image for the header, which will hopefully answer your off-note.
Excellent! I'll have to share a link to your website for your epic assistance.
Thanks bro!
Abe
Beer and backlinks… you're spoiling me, Abe!
Glad you got it working – the site's looking awesome!
Hi Dan, thanks for taking care of us CSS newbies! =)
I love Divi and I already used it to build a few sites – sometimes I did some basic customization getting mad with the editor, but finally getting it even if after thousands of trials and mostly errors.
One thing that I cannot manage to customize is the size of the Fullwidth Slider. I like it as it is, but one of my clients is asking me to reduce its height, so to make visible also what's below to users who land on the homepage. I'd like to take it down to 400-450px max – is there any CSS command I can add to reduce its height?
Thanks in advance for your support!
Hey Massimo! Someone has to look after you guys =p
I've added a section above on changing the height of the Divi slider.
Hopefully that is enough for your needs. It should be if your client's images have the right proportions for the new height, but let me know if there are any more adjustments you need to get the look right (scaling images, etc).
Hi Dan,
You have created a very useful page here, thanks. I'm fairly new to Divi and still testing it out. I'm also having problems with the full width slider. You mention its a fixed size, but it has to be responsive for mobiles etc. so would your solution require an @media or did you have something else in mind?
The main problem I have is ensuring the image fits correctly on all devices. It never does and its proving very frustrating. Any tips greatly appreciated.
Cheers. Steve
Hi Steve,
I've just updated the code for changing the slider height. I've added a media query so that my fix only applies on desktops. On mobiles, it defaults to the standard Divi slider height. This works better than what I had before, but I'll look into this further at some stage and see if I can improve the look on mobiles (perhaps maintaining the same width to height ratio as for the desktop slider). Hopefully my update is sufficient in the meantime.
Is there a way to remove the divi logo on the home page without removing the entire banner or without having to put another logo in its place?
Hi Andy, you can remove the logo completely by adding the following CSS:
How can you add a header image above the nav? I've been trying all types of things. Ideally, it could be large, like the size of the slider but full width.
Hi brendan, I've added a section above describing how to add a full-width image above the header bar. I hope that achieves the affect you are after.
Hi Dan,
Is there a way I could add a widget in the header section (on the right) because I will not be having any links being shown in that area.
Thanks.
Hi R, I've added a section to the post above describing how to replace that header section with a widget area. You can then add your widget to the new widget area (named "Header") in your WordPress dashboard widgets page.
How do you center an image on a page? i see that there is no alignment options there.
and How do you remove the header permanently. I prefer to have the page with no header, just plain content.
Hi gallager,
Which images are you trying to center? If you can point me to an example, I should be able to help you out.
To remove the Divi header, you can add the following CSS:
Hi Dan
I'm new to CSS. Is it possible to change the font size in only one text module with CSS in Divi?
Thanks
Hey Brent,
You can do it like so:
You just need to change it to use the id of the page / post you wish to target, then set the correct indices in the nth-of-type() parts to correspond to the page builder section, row, column and text module you wish to change the font-size on.
i'm using Divi 2.0.
How can I show a caption instead of the title when viewing the full size image from a gallery? Thanks for any help.
Hi h4ns3n. You can make the gallery show the caption instead of the title by changing this bit of code (located around line 3625 of the Divi functions.php file):
To:
Note that all I've done is change the "post_title" part to "post_excerpt".
please help…
I am a wordpress Developer and want help below what i want
i want to make some changes in blog section of divi theme i am enable to find file from which blog is coming can anybody help me
Thanks In advance
Hi sachin22. The main listing of blog posts displayed on the Divi homepage is generated by the following file:
Hopefully that is what you're looking for…
Hi,
I wanted to create a new widget area in the main header. Is there a way to use the sidebar module for the main header? I try the snippet codes but it does not works in the function.php. Or maybe I pasted wrong codes or place. Can you help?
Check out the snippet codes
Note: I have added prefix wpgyan_ to function name at two places at top and at bottom.You can change to a prefix of your choice.
2. Display Widget Area
To display Widget Area add following code to location of your choice in your theme file.
Where:
header_sidebar is id of Widget area in Step 1.
If this is the correct codes, where do I paste them at? I've tried to pasted after the code below:
But It does not work then have a parsor error. Help!
Thanks,
Michael
Hi Michael, It looks like your code is missing some bits – I'm not sure if they have just been lost in the copying and pasting though…
Anyway, I've added a section to the post above describing a (slightly) different way of adding a widget area to the Divi header. It should achieve the same effect that I think you're going for. Let me know if you have any trouble with it.
How do I remove the permanent header in Divi?
Also, how do I center position images?
Hi farmfoodie,
By permanent header, do you mean the one which starts off big, but then shrinks when you scroll down a bit? It looks like you've now managed to disable this from within Divi's control panel, am I right? Another (less ideal) way to do it is by adding this the end of the Divi theme's style.css file:
With this, when you scroll down the header will disappear instead of shrinking.
(Note that the transition isn't as smooth as I'd like, so when I get a chance I'll try and improve this).
If you want to center images within posts, you can select choose "center" alignment when you add the image to the post, or hover over an image you've already added, and click on the "pencil" icon that appears. You will then be taken to the image edit screen where you can again select "center" alignment.
If you want to center an image which the user has clicked on (and is the only thing now displayed in the tab), I'm afraid you're out of luck as this is the browser displaying just the image and nothing else (so there is no way to add commands to center it). One option in this case is to look for a plugin which displays images in a nice centered overlay on the page. I haven't used any to recommend to you, but maybe something like this might work: Thumbnail Viewer Plugin.
I hope I've understood what it is you're trying to do, and been at least partially helpful!
Dan
Hi There!
Have you tried using the "blurb" module instead of the image one.. this centres the image automatically for you instead of having to use CSS. Just upload the image and don't add any text on it. Hope that helps!
Thanks,
Dave