Pages

Rewrite and Redirection by .htaccess


Force www


RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

Force www in a Generic Way


RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
This works for any domain.


Force non-www


It's still open for debate whether www or non-www is the way to go, so if you happen to be a fan of bare domains, here you go:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

Collection of WordPress Template Tags

WordPress Themes are files that work together to create the design and functionality of a WordPress site. Each Theme may be different, offering many choices for site owners to instantly change their website look but they are made up with simply following functions.

the_title()
Displays the posts/pages title
the_content()
Displays the content of the post/page
the_excerpt()
Displays the excerpt of the current post/page
the_time()
Displays the time of the current post/page

Truncate and break at word

This will attempt to shorten a string to $length characters, but will then increase the string (if necessary) to break at the next whole word and then append an ellipses to the end of the string. Good for shortening readable text while keeping it looking pretty.
function truncate($string, $length) {
    if (strlen($string) > $length) {
        $pos = strpos($string, " ", $length);
        return substr($string, 0, $pos) . "...";
    }
    return $string;
}
Use :
echo truncate('In the above example, the resultant output will be the quick brown…, because the 10th character is the space immediately before the ‘b’ in ‘brown’, which is counted as part of the word ‘brown’.', 100);