in

How to Optimize WordPress Theme: 10 Useful Tips

Optimize Your WordPress Theme, which falls under the right action in context to buoy up the first impression of your site powered by WordPress. It should be always keep in mind that the users are not going to put strain on their mind as well as stay with any site or page which is not affable to them. However, almost all website owner wish as well as strive to render their website more engaging and appealing. Therefore, various WordPress Theme are available over there which helps a lot towards this direction.

Undoubtedly, one of the WordPress’s great achievement is the ability to adapt with distinct tasks in very easy and convenient way. Beyond this, you can easily upgrade it in account of some fragments of code. Below I have designated some snippets of code that will quite obvious for you to Optimize WordPress Theme and can be easily included to your WordPress theme’s functions.php. So, go ahead and take a tour over this 10 Useful Tips that lets you enable to Optimize WordPress Theme and opt to employ which have capability to fulfill your need and requisite.

Limit The Word Count of Excerpt

With WordPress magazine one thing is found to be confounded with so many words when the users attempt to include before more tag. Undoubtedly, they could optimize excerpt towards that specific field, but quantity of posts comprises by a website where the text above “more tag” has been always employed, however it seems to be confounded towards  creating  excerpts for all post manually. Therefore, in context of this case, by employing this code you can check the words number which display in the excerpt.

add_filter('excerpt_length', 'ilc_excerpt_length');
function ilc_excerpt_length( $length )
{
return 10;
}

At this place, we are employing a filter hook of WordPress, that will excellently modifies or parses the data before appeared on a page or saved in the database. This snippet of code will show 10 words in the excerpt.

Using A WordPress Hook Include A Favicon

Now, Inserting a custom code with WordPress Hook is possible without fingering the template. It is very flexible and easy to implement because in this direction only you will have to alter the function which is plugged in particular hook. For illustration, Simply in account of incorporating a function you may include a favicon to a website you owned in the hook of wp_head and without interfering in the header.php file.

add_action( 'wp_head', 'ilc_favicon');
function ilc_favicon()
{
echo "<link rel='shortcut icon' href='" . get_stylesheet_directory_uri() ."/favicon.ico' />" . "\n";
}

This faviocn.ico file mut be stored at the theme’s root. Now, we are employing an hook of action and is referred as a function to triggered at a particular point in an execution led by WordPress core. For instance, when a page is being launched in browser the hook can bring out any function which is incorporated by it. However, the other hooks may be activated during registering a user, saving a post and miscellaneous. Some of the WordPress themes also incorporates their own hooks of action, such as the core action of WordPress’ hooks, that can be implemented to call functions in the execution at particular points.

Designate Safari On iOS

In recent, websites also cater mobile versions employing distinct techniques. WordPress implement a very impressive method to analyze for browser of mobile Safari which lets you acquainted that when a user is employing iPad or iPhone.

WordPress designate the $is_phone variable internally and allows you to show alternative content, embed an optional style sheet or show a distinct video format. However, In below listed illustration, the $is_iphone variable execute and by the result obtained from value returned implement distinct style sheets.

add_action('wp_print_styles', 'ilc_enqueue_styles');
function ilc_enqueue_styles()
{
global $is_iphone;
if( $is_iphone )
{
wp_enqueue_style('iphone-css', get_stylesheet_directory_uri() .'/iphone.css' );
}
else
{
wp_enqueue_style('common-css', get_stylesheet_directory_uri() .'/common.css' );
}
}

Here, we are using the WordPress’ standard function of wp_enqueue_style to include styles to Web page’s head element. We are attaching the action of wp_print_styles function, however, the WordPress is being intimated to display the concerning style sheet as it used to print other style sheets.

Eliminate Components From Header

In the head section WordPress displays many things. Specifically, “generator” meta tag, wlwmanifest link, the RSD link which is not significant for much users.

<meta name="generator" content="WordPress 3.2.1">
<link rel="EditURI" type="application/rsd+xml" title="RSD"href="http://example.com/xmlrpc.php?rsd">
<link rel="wlwmanifest" type="application/wlwmanifest+xml"href="http://example.com/wp-includes/wlwmanifest.xml">

Many bloggers recommend to forgo ‘generator meta tag’ through which anyone can predict what version of WordPress you are using. But, employing WordPress latest version is highly recommended. You can eliminate the RSD link in case you don’t require XML-RPC functionality. If you are not accessing Windows Live Writer employ the same function. Moreover, you can also delete the third element safely. However, with this scenario you can include below listed code.

add_filter('the_generator', create_function('', 'return "";'));
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');

This fragment of code will result in eliminating the concerning elements in the above snippet.

WordPress To FeedBurner Feeds

It is a great news that WordPress also allows feeds. However, in order to have a report on statistics of your subscribers, you are required t employ FeedBurner or an identical service. Also, by using the below snippet you can migrate your feed as following. Hence, when you will supposed to go https://www.webgranth.com/feed, you will be migrated to FeedBurner’s feed for Webgranth.

add_action('template_redirect', 'ilc_rss_redirect');
function ilc_rss_redirect()
{
if ( is_feed() && !preg_match('/feedburner|feedvalidator/i',$_SERVER['HTTP_USER_AGENT']))
{
header('Location: http://feeds.feedburner.com/webgranth');
header('HTTP/1.1 302 Temporary Redirect');
}
}

Display Featured Images In Feed

Towards encouraging your subscribers to visit your site, you can display only featured image of the post and excerpts rather than of content from your RSS feed. However, by default the RSS feed doesn’t show the feature image of the post, but you can actuate it by means of following code. Even you can include HTML to it.

add_filter('the_content_feed', 'rss_post_thumbnail');
function rss_post_thumbnail($content)
{
global $post;
if( has_post_thumbnail($post->ID) )
$content = '<p>' . get_the_post_thumbnail($post->ID, 'thumbnail') .'</p>' . $content;
return $content;
}

Content Visible to Only Logged-In Users

In the same array, you can transform the content of your site visible only to the registered users. The below provided code generates a novice shortcode which hide the content for casual visitors and visible to logged-in users.

add_shortcode( 'loggedin', 'ilc_loggedin' );
function ilc_loggedin( $atts, $content = null )
{
if( is_user_logged_in() ) return '<p>' . $content . '</p>';
else return;
}

Show Content Only to RSS Subscribers

In order to elevate the number of subscribers to your RSS feed, you may deliver a reward only to them. In account of below listed code a new code will be generated which checks regular visitors except your RSS subscribers to view the content.

add_shortcode( 'feedonly', 'ilc_feedonly' );
function ilc_feedonly( $atts, $content = null )
{
if( is_feed() ) return '<p>' . $content . '</p>';
else return;
}

Enrich The Log-In Page with Logo

You will be pleased to know that you can incorporate your logo in log-in page through employing login_head action hook, that results in executing other functions which are included to it in the Log-in page’s head element. Now, we are going to implement here two things, modifying the logo and altering the concerning link.

add_action( 'login_head', 'ilc_custom_login');
function ilc_custom_login()
{
echo '<style type="text/css">
h1 a { background-image:url('. get_stylesheet_directory_uri() . '/images/login-logo.png' . ') !important; margin-bottom: 10px; }
padding: 20px;}
</style>
<script type="text/javascript">window.onload = function(){document.getElementById("login").getElementsByTagName("a")
[0].title = "Go to site";}';
}

What do you think?

Written by Leander crow

Comments

Leave a Reply

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

Loading…

0

Comments

0 comments

Google’s Social Media Analytics to Analyze Social Media Traffic

Blogger Tutorial to Setup FeedBurner on Blogger