How to display excerpt with fixed character length?

How to display excerpt with fixed character length?

WordPress shows 55 words in its default excerpt. What if you need to limit the character length of the excerpt in WordPress instead?

When do you need to fix the character length of the excerpt?

You know that some words can be very long and some short. Because of this, default excerpt of the WordPress varies in character length. There are some cases when you need to have excerpt of fixed lines. For example, you want to show posts in gridview and want all the post grid with same height. (You can take the homepage of our website as an example.) In this case, you have two options, either fix the height of grid by CSS and hide the overflowed text (as done in our website) or pull excerpt with fixed character length only.

Here, we are going to learn how to get excerpt of fixed length of character.

How to display excerpt with fixed character length?

You can do this with the help of a simple function. You need to put this function in the functions.php of or your theme and then call it whenever you need excerpt with fixed character length.

Here’s the code of the function:

  // For excerpt with charlength as asked
function the_excerpt_max_charlength($charlength) {
	$excerpt = get_the_excerpt();

	if ( mb_strlen( $excerpt ) > $charlength ) {
		$subex = mb_substr( $excerpt, 0, $charlength - 5 );
		$exwords = explode( ' ', $subex );
		$excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
		if ( $excut < 0 ) {
			echo mb_substr( $subex, 0, $excut );
		} else {
			echo $subex;
		echo '[...]';
	} else {
		echo $excerpt;

Now, wherever you need to echo excerpt, you need to call this function:

<?php the_excerpt_max_charlength(140); ?>

In above function call, you’re sending 140 as parameter. This parameter is actually the character length that you want to be shown. Sending 140 as parameter echos excerpt with 140 characters.

Wrapping Up

Limiting the character length of excerpt helps in different contexts. This easy to implement function is what I am using in my projects. You can try it in your site. If you have any question about it, you can put them below in the comment box. I’d love to help you as far as possible.

Lots more important posts are awaiting you. So, keep following WPCounsel.

How to add advanced meta box to your WordPress theme

How to add advanced meta box to your WordPress theme

If you’re WordPress theme customizer, you should have come to the situation when you need to add advanced meta box to certain post types of your. You can easily create simple post types with input field, textarea, radio buttons, checkboxes, etc. But, what if you need some complex options like file uploader? You’d have to struggle a lot to get things right, isn’t it?

Well, recently while building a WordPress theme for one Podcast website, I came across with similar situation. I had to struggle a lot for right coding for brilliant audio uploader field in the metabox which I had to place for ‘post’ post type. I wrote code myself but couldn’t get satisfied completely with it. On the other hand, I was on the tight deadline as well. As per my motto, I must give brilliant service to my clients. So, how would I do it?

Meta Box plugin!

Yes, sometimes plugin is what fits best to your requirements. And you get the right free plugin available in WordPress plugin repository, what would you look for?

I installed Meta box plugin and looked for its menu. I was too much surprised when I didn’t find any menu of this plugin. Now, how would I create meta box? I again googled about it. And, soon I landed to Online generator of page of it’s official website.

Online generator of Meta box plugin

I started to fill up the form as per my requirement. I was so much surprised when I saw huge range of fields for meta box. It has all sorts of powerful field ranging from input fields to file advanced, image advanced, taxonomy, user and many more. What I needed was a text input field and a file advanced field. I clicked them, arranged them and finally hit on the ‘Genarate Code’ button. I got pretty clean code.  After this all I had to do was paste this code to functions.php file.

fields in online generator of Meta Box plugin

Bingo! I got awesome meta-box without any hassle. And, as it’s well tested and well-developed plugin, I need not worry about quality. I found it really awesome!

Wrapping up

Sometimes, plugin is what you are exactly looking for. And, Meta Box plugin is so much powerful that you need not worry about anything. Well, there would be problem if your clients don’t install it. So, for this issue, I placed TGM Plugin activation in the theme and configured it to ask theme user to install Meta Box plugin from WordPress repository. Pretty simple right?

We’ve lots more WordPress resources coming up. So, keep following WPCounsel.

How to move Comment box field below other fields in WordPress comment form

How to move Comment box field below other fields in WordPress comment form

By default, WordPress comment field has comment box (Textarea) above other fields (name, email address and URL). Do you know how to move comment field below other fields?

Comment form with comment box above

Comment form with comment box above

I was recently developing WordPress theme for a Podcast website. I was provided HTML/CSS theme and was hired to convert it to WordPress theme. As per the design, I’d to place comment box below other fields. But, WordPress by default outputs comment box above. So, I needed a solution to solve this issue. After doing some research, I found an easy fix for this issue. I’m calling this an easy fix because all you’ve to do is place a function in functions.php and then you’ll see the magic!

Here’s the code (with function) that you’ve to add in functions.php of your theme:

function wpc_move_comment_field_to_bottom( $fields ) {
$comment_field = $fields['comment'];
unset( $fields['comment'] );
$fields['comment'] = $comment_field;
return $fields;

add_filter( 'comment_form_fields', 'wpc_move_comment_field_to_bottom' );

After you add above code in functions.php, comment field automatically moves down. This is how comment box looked in the website after I added above code:

Comment form with comment box below

Comment form with comment box below

Isn’t is really simple?

Wrapping Up:

If you have any question related to this post, please leave a comment below. I’d love to hear your comments and help you to the fullest. And, keep following WPCounsel for the latest WordPress resources.

Best Free WordPress Blog themes 2017

Best Free WordPress Blog themes 2017

Are you looking for the best free WordPress blog themes? If you’re, you’re in the right page. Here’re I’ve listed the best WordPress themes for blogs which I discovered after plenty of research and testing. I’m sure this list will help you find the right theme for your blog.

WordPress was originally developed for blogs. But, it didn’t limit its scope to blogs. Every types of websites have been built with WordPress these days ranging from personal websites to business websites, ecommerce sites, news portals, web directories, knowledge base and much more. This is what enabled WordPress to power about 30% of total websites in the world. Although, WordPress has covered entire website industry, blogging is still the most preferred use of WordPress. So, WordPress developers are still focusing to develop more powerful and elegant blog themes.

More reading: Free theme vs Premium theme – which is better for my website?

Here are the best free WordPress blog themes for 2017:

Hueman – Free WordPress Blog theme

Hueman - Free WordPress blog theme
When it comes to free blog theme, Hueman is one of the most popular theme of this category. It comes with a multi-column layout which you cannot find in normal free themes. You can use Hueman for any kind of content rich blogs or even the magazine websites.

Another great advantage with Hueman is its better customization options. You have options for custom headers, two column layout, full width layout, and tons of other easy customizations. I highly recommend you to give it a try.

Bento – Free WordPress Blog theme

Bento - Free WordPress blog theme

Bento is yet another great free WordPress blog theme with tons of features. The best feature is its supports all page builder plugins seamlessly and even recommends one after installation. With the page builder plugin, you can create beautiful and powerful pages yourselves with simple drags and drops. This makes Bento a multipurpose WordPress theme as well.

Bento is customizer based WordPress theme. This makes Bento more advanced and easily customizable. You can live preview of any changes that you do and save changes only when you’re are happy with them.

Peaceful – Free WordPress Blog theme

Peaceful - Free WordPress Blog theme

If you’re looking for minimalist blog theme, Peaceful is the best one of this segment. It’s fully responsive theme because of which looks brilliant in all devices. Besides, it features a single column layout, large header image, a compact navigation menu, and elegant featured images. Its so easy to setup this theme that a complete WordPress newbie also can do it easily.

Wisteria – Free WordPress Blog theme

Wisteria - Free WordPress blog theme

If you want simple looking blog, Wisteria is best for you. It is simple and elegant theme which focuses on beautiful typography and content. You can choose custom background, colors, custom headers and sidebar. Wisteria has single navigation menu on top with beautiful homepage featuring posts with featured image and custom excerpts.

Nisarg – Free WordPress Blog theme

Nisarg - Free WordPress blog theme

Nisarg is another elegant free WordPress blog theme. It supports two navigation menus and has large full-width header image. In addition to that it supports custom background image and colors as well. Nisarg  is fully customizer based WOrdPress theme and thus allow live preview during customization. You get multiple post formats for videos, gallery, audio, chat, aside, quote, etc.

Juno – Free WordPress Blog theme

Juno - Free WordPress blog theme

Juno is the free WordPress blog theme with premium features like slider area, masonry style blog and much more. You can easily customize colors and fonts as well. It is fully responsive WordPress theme because of which you need not worry about having different websites for different versions.

Another great feature of Juno is that it support WooCommerce. Because of this you can sell products and services easily from your blog. Isn’t it great?

Wrapping up

If you are starting a blog, you can start with any one of the above WordPress theme. This way, you can save money as well as get good quality (as these themes are well tested by brilliant theme review team and thus are bug and loophole free). If you later would like to improve design and functionality, you can always do that hiring a freelancer or by purchasing and using premium theme.

We have lots more WordPress resources to be published. So, keep following WPCounsel.

How to edit .htaccess file of WordPress website from WordPress Dashboard

How to edit .htaccess file of WordPress website from WordPress Dashboard

.htaccess is the configuration file of Apache web server which defines who can/cannot access files of the website. Besides, it also defines the permalinks of the website using WordPress. You generally need not touch .htaccess file. But, in some case you are asked to add certain code in the .htaccess file. In such situation, you generally face trouble as you need to have either FTP connection to your web server or need to have cpanel access.

Do you know that you may already have the tool to edit .htaccess file of your WordPress website?

Yes, if you have installed Yoast SEO plugin, you already have a tool to edit .htaccess file. In this article, I’m going to show you how you can do  it easily from Yoast SEO plugin. Now, let’s begin.

Step 1:

Log in to the WordPress Dashboard.

Click on the SEO >> Tools menu.

Open tools menu of Yoast SEO

Step 2:

You’ll land on the Tools page of Yoast SEO.

Click on the File Editor as shown on the following screenshot.

Click on File Editor

Step 3:

File editor of Tools page opens. This page allows you to edit Robots.txt file and .htaccess file as shown in this screenshot.

Edit .htaccess file and save changes

After you edit the .htaccess file, click on the Save changes to .htaccess button.

Congratulations! You have successfully edited .htaccess file of your WordPress website from your WordPress dashboard.

Wrapping up

You shouldn’t edit .htaccess file unless you’re suggested from credible source or you know exactly what you are doing as it is very critical file. If you’ve any question or suggestion, kindly put that below as the comment.

We’ve lots more articles related to WordPress on the way. So, keep following WPCounsel.