Directory Image
This website uses cookies to improve user experience. By using our website you consent to all cookies in accordance with our Privacy Policy.

WordPress Functions That Make Blogging Efficient

Author: Deepa Ranganathan
by Deepa Ranganathan
Posted: May 18, 2015

If you want to modify the Wordpress theme, you will need to offer customization in the function.php file within the theme. Within this file, all the relevant data related to the theme is present, and accepts unlimited number of modifications. You can get this file within the themes folder of your Wordpress website.

If you want to customize your blog's behavior, then you will need to customize this file. When you customize this theme file, you get to customize a lot of options within the blog. You have better control on the customizations when you opt for creating changes within the functions.php file.

Using Shortcodes

Shortcodes were basically introduced in order to make customizing files and folders within a theme easy and convenient. Let's add a function to the functions.php file in your theme folder and give it a name. you can later call this function using the code add_shortcode, and using the assigned name call the shortcode within the function

// Creates our function

function ExampleShortcode(){

Code we want to process hereā€¦

}

// Registers our function with the shortcode. First parameter is the shortcode name, the second is our function name.

add_shortcode('example','ExampleShortcode');

Using [example] you can easily process this function in a post or page. Now that you know how to use shortcodes, let's see which functions help boost the functionality of your blog.

Adding Links to your Posts

It is a habit of a great blogger to link other articles related to the current post. What happens in most cases is that you tend to share the link of the other article within the post. As your post base increases, you keep increasing the number of links within a particular post.

Let's say, while you are at it, the address or directory structure within the blog undergoes a change. This simply means, you will need to change the links within the post manually. Now, that can be a tad bit difficult, changing everything manually. Instead of making the links static, try creating dynamic links using a simple function get_bloginfo('wpurl')

You will need a shortcode to perform this customization

function BlogAddress(){

return get_bloginfo('wpurl');

}

add_shortcode('url','BlogAddress');

With this URL shortcode added to the links within the blog post, you will see that the link remains despite changes in the directory. The settings within the shortcode will be modified within the settings whenever the directory structure or the blog address changes. With this shortcode, you are saved the efforts of changing all the links within a blog manually, every time a small change occurs in the blog.

Immobilize Modification of Source Content

Let's say you wrote a post in word, and then pasted it to your blog. What happens in this case? Your blog takes on a strange behavior and starts add the
towards the end of every line break. A break is added to every line, whether it ends in a paragraph format or not. This can cause a lot of formatting errors within the post, making it look bad.

There are several methods that you can use to change the behavior of your blog, but how about disabling this thing for good? Add the following code to your functions.php file and you can make sure the source code modification is disabled

remove_filter ('the_content', 'wpautop');

this filter that is being added disables both

as well as
tags that offer line breaks. This code will modify the posts and pages that are shown to the users. If you want to change the post excerpts as well then add the following code

remove_filter ('the_excerpt', 'wpautop');

With this code added, all the pages within the blog will follow the code that you have added. Since you have added this filter, you will need to add the breaks yourself. So, you will need to first plan where all you need the break and add them accordingly. In case you are new to Wordpress, you may not want to add this filter, as you are never sure when and where to add the breaks.

Render the Fancy Characters Inoperative

Sometimes Wordpress adds quotes, dashes and other special characters within your blog. This can be quite irritating, especially when you don't want them in your blog post. When you add the HTMKL block code to your post or page, you will see that the wptexturize function has a habit of replacing single and double quotes with fancy characters. In case, you have just pasted the block code from someplace else, you run the risk of including the fancy characters within your blog post. While replacing the regular blocks with some fancy characters does make your blog look good, adding it everywhere can ruin the appearance. Also, you as the author should decide when the blog should include the fancy characters, and when it should refrain from doing so.

You can easily disable the fancy characters from the functions.php file in your theme folder. Add the following code to your functions.php file

remove_filter ('the_title', 'wptexturize');

To remove the fancy characters from wthin the content of a particular post

remove_filter ('the_title', 'wptexturize');

If you want to remove the fancy characters from within all the posts

remove_filter ('single_post_title', 'wptexturize');

remove_filter ('bloginfo', 'wptexturize');

remove_filter ('wp_title', 'wptexturize');

remove_filter ('category_description', 'wptexturize');

remove_filter ('list_cats', 'wptexturize');

remove_filter ('comment_author', 'wptexturize');

remove_filter ('comment_text', 'wptexturize');

remove_filter ('the_title', 'wptexturize');

remove_filter ('the_content', 'wptexturize');

remove_filter ('the_excerpt', 'wptexturize');

Remember, you will need to choose from where and how you want to remove the filter. Don't disable the code from the HTML code in case you are not going to share the same with your visitors.

Deepa is a passionate blogger associated with Semaphore Software. She loves sharing information regarding WordPress tips & tricks. If you are looking for Hire Dedicated WordPress Developers then just get in touch with her.

About the Author

Deepa is a technical writer with Semaphore Software.

Rate this Article
Leave a Comment
Author Thumbnail
I Agree:
Comment 
Pictures
Author: Deepa Ranganathan

Deepa Ranganathan

Member since: Mar 29, 2015
Published articles: 42

Related Articles