How to test a wordpress theme without changing it for live visitors

Is your site’s current theme is very slow or does it has too many glitches or you are unsatisfied with your site’s appearance? For any of such issues all you can do is go for a new theme or debug and work on your current theme. To debug you need some technical skills, but switching a new theme is very simple as it only takes a minute to setup. As an administrator you would always like to offer a better experience for your users by improving the site speed or by tweaking the design etc. If you are building a wordpress website from scratch then there is no trouble in changing or testing various themes because nobody is going to see it, but what about a live site where you are receiving thousands of visitors a day. Here let’s see how to test a wordpress theme without changing the existing theme for live visitors.

There are several high quality websites like Theme Forrest, Elegant themes, Themify, Theme Fuse and Mojo themes etc where you can find the best themes to suit your blog or website. Let’s assume that you have bought a nice fascinating theme and you would like to run it on your live website. Usually setting up a new theme in a live site is very stressful because you do not know when the theme causes trouble and tends to break something. Also attaining the desired look from the theme will take few days or even a month depending on your creativity.

So how to test your new theme; you can test it in a dummy domain, but what if you don’t have one. You can test it in local computer which most developers do and we have tutorials for that, but this takes a long process and it’s not recommended for beginners. For instance here is how to setup wordpress on localhost using WAMP and here is how to clone a live wordpress site to localhost, but here comes the better way. By using a plugin you can preview and test your theme in live environment without changing your site’s appearance or without showing any errors to your regular users.

Theme test drive – Test a wordpress theme

Theme test drive plugin allows you as an administrator to safely test themes in your website, while your regular users still use the default one. The process is completely hidden and nobody will know that you are using or testing a different theme. First install and activate Theme test drive plugin in your site and upon activation you will see an option called Theme test drive added in your Appearance section. Open the theme test drive plugin page and install the new theme that you are about to test.

How to test a wordpress theme without changing the running theme

No problem if you have already installed the theme in your site, just at the bottom select the theme to preview or test live on the site. Note that only Administrator can see the selected theme and the remaining folks will see the actual theme that you have activated. After selecting the theme click on enable theme drive and now check your site where you will see the theme that you have chosen, go on and start working on your new theme.

Theme test drive, testing themes in live environment, Theme tester

Also read: How to change the wordpress theme name

The best part is you can test any theme that you have installed in your site. For example just add?theme=default next to your domain name and it will bring the default theme. Then replace default with some other theme name that you have installed and it will bring you that theme. Next is access level where you can specify the level of users to have access to the selected theme preview. Set it between 10 to 1, for example 10 is for administrators, 7 is for editors, 4 is for authors and 1 is for contributors.

Wordpress theme preview, theme test drive, test a wordpress theme in live site

Also read: WordPress user roles and Capabilities

That’s it, you start working on your new theme and the rest of the people will use your standard theme. Hope this post helped you to test a wordpress theme in live site without disturbing the traffic.

Adding Feedburner email subscription form in wordpress and Blogger

Adding Feedburner email subscription form in wordpress and Blogger

You will start to receive some good traffic flow when you keep on publishing quality content in your website. Whether you are a professional blogger or blogging for hobby there are some folks who always stick to your blog and love your writings. Since you blog more often the main goal should be building a community of peoples and that is what converting visitors to subscribers is. Readers who love your blog will be looking for a way to get latest updates straight in their inbox. So by adding an email subscription form people who are interested will start subscribing and automatically receive content whenever you update in your blog.

Feedburner is a service by Google that lets visitors to subscribe to your blog feeds. By adding this email subscription form in your sidebar people start to subscribe by entering their email address. After they subscribe, a verification email will be send to them in which they have to confirm the subscription and when done Feedburner automatically starts delivering the latest content. Feedburner email subscription widget will help you to build a mailing list effectively, so if you don’t have a subscription form in your website then it’s time to add one. Hold on! First do you have a Feedburner account if not its simple to setup one. Here is how to setup Feedburner feeds for wordpress and here is the guide to setup Feedburner for Blogger. In this post we will see how to add Feedburner email subscription form in wordpress and Blogger.

In both those tutorials we have mentioned our users to enable email subscription so that they can offer feed updates via email. Here are some other Feedburner tutorials which would be helpful for you in later. Setting up Feedburner email subscription form is very simple and for those who can’t figure out here is the quick tutorial to setup a basic Feedburner email widget.

Setting up Feedburner email subscription form

Before you can setup the email opt-in you have to enable email subscriptions. Login to your Feedburner account, navigate to publicize tab and then enable email subscriptions. Next in subscriptions management you will see a code like this, just copy that and follow the instructions below to add in wordpress and in Blogger.

1 <form action="http://feedburner.google.com/fb/a/mailverify" method="post" target="popupwindow" onsubmit="window.open('http://feedburner.google.com/fb/a/mailverify?uri=BlogTimeNow', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true"><p>Enter your email address:</p><p><input type="text" name="email"/></p><input type="hidden" value="BlogTimeNow" name="uri"/><input type="hidden" name="loc" value="en_US"/><input type="submit" value="Subscribe" /><p>Delivered by <a href="http://feedburner.google.com" target="_blank">FeedBurner</a></p></form>

Adding feedburner subscribe box

WordPress: Login to your wordpress dashboard, go to appearance >> widgets, drag the HTML text widget to your sidebar and then save it. For wordpress you have a plugin called Feedburner optin Form, you can try that too but that is not required in most cases. If you have some knowledge in HTML and CSS then you can simply style your subscription box to suit your blog.

Blogger: Login to your Blogger account, choose your blog and from dashboard go to Layouts. Now click on add a gadget, select HTML / JavaScript gadget and then place the code in that’s it.

Feedburner subscribe box widget

After adding the code go and check your blog sidebar where you can see the Feedburner subscription form which looks very plain. So by using HTML and CSS you modify the appearance of the subscription box. Now enter your email and subscribe for yourself to see how it works. Hope this helped you in adding Feedburner subscription form in wordpress and Blogger, what’s next. Know how to setup Feedburner Mybrand for your own domain and knowhow to export email subscribers list from Feedburner.

How to insert / embed Bing maps in your website (wordpress / Blogger)

How to insert / embed Bing maps in your website (wordpress / Blogger)

Here at Blog Time Now we have seen many embedding tutorials such as embedding Google maps in Blogger,embedding Google maps in wordpress, embedding Facebook videos in a website, embedding SoundCloud in Blogger andembedding media files in wordpress. All those tutorials are made easy and that is because all sites simply offers an code in which you can easily embed objects anywhere without spending too much time and effort. Embedding Bing maps are easy too! Here we will show you how to insert / embed Bing maps in your website that is on both wordpress as well as Blogger.

Almost, not certainly both Google and Bing offer products and services that are similar to each other. They both as a search engine offers web search, image search, video search, news, maps, webmaster tools, translator and more. Bing is a nice alternative to Google and for anyone who got tired of using Google can go for Bing. But to be frank, In Bing the features are less when compared to Google products. Alright! Let’s focus on the topic, about embedding Bing maps.

Also read: How to use Bing webmaster tools

In Bing maps you can quickly and easily get directions, find businesses as well as locations. Similar to Google maps, in Bing you will get features like road map and satellite map, other than that you will also have different options to view and embed maps such as street view, bird’s eye and Ariel view. If you find Bing maps to be useful for your visitors then you can simply embed it in your website.

Insert / Embed Bing Maps in website

Bing maps are free to use, share and embed. First go to Bing Maps . The interface in Bing is pretty much same as old Google maps. Before you can embed the map, you have to first spot the location. To find the location you can use the search bar or you can simple drag and zoom the map to exact location that you are looking for.

How to insert Bing maps in Blogger - How to embed Bing maps in wordpress

After spotting the location you will have several options just above the map such as road map, bird’s eye, aerial, traffic and street view. Next at the top right corner you will see share option, just click on that and a window popups. Now you can see the embed code; wait a second don’t copy that, to get the accurate map results click on customize and preview.

Embedding Bing maps in wordpress and Blogger, Bing maps for website

Now a separate window will open where you will have several customizing options. Choose whether small or larger map or you can even go for a custom size. Choose map options that is whether the map is draggable (draggable map will have the ability to pan and zoom) or static. Choose map style that is whether road map or aerial map, remove map links if you want and when the preview result is ok, then finally click on generate code. Now you will get a embed code in another window, just copy that and then proceed to next step.

How to embed Bing maps in a website, Inserting Bing maps in wordpress and Blogger

How to embed Bing maps in wordpress

How to embed Bing maps in to a website, Inserting Bing in wordpress

You can easily embed Bing in your wordpress posts and sidebar. For example if you wish to add the map in a page or in your post, go to wordpress dashboard >> posts or pages and then switch to text editor. Now paste the code that you generated in Bing and when done publish your post. So the result will be like this.

If you wish to add it in your sidebar then go to Appearance >> widgets, move the Text widget to your sidebar and then paste the embed code in. But make sure to adjust the map size that is to fit your sidebar.

WordPress plugins to embed Bing maps

Wordpress plugin to embed Bing maps, Leaf lets maps marker usage

For wordpress there are several plugins to embed maps, but one thing that has more options isLeaflet maps marker . Leaflet maps marker allows you to embed Google maps, Bing maps and open street maps in to your wordpress site. With Leaflet maps marker you can mark, pin and show off your business address or any other favourite places to your site visitors. Using this plugin is fairly simple, you can get whole plugin documentation and support at mapsmarker.com .

How to embed Bing maps in Blogger

Embedding Bing maps in Blogger is same as what we did for wordpress, but for Blogger you don’t have any plugin or gadgets to add further features. Go to bing.com/maps, choose map size, select maps style and after customizing as per your needs, generate the code and grab it. Now go to your blogger blog. Embedding maps in contact us page will help your visitors to find directions. For example go to dashboard >> pages create or open contact us page, switch to HTML editor and paste the embed code. The same way you can embed Bing maps in to your blog posts.

How to embed Bing maps in Blogger website, Embedding Bing Maps

If you wish to embed map in to your sidebar then go to Layout >> add a gadget, choose HTML/JavaScript gadget, add the embed code and then save arrangements.

Hope this post helped you on how to insert / embed Bing maps in wordpress and Blogger. Please share it and if you have any other questions, then feel free to ask us using comments below.

Urgent WordPress Security Tips

Urgent WordPress Security Tips

Concerning dealing with your website, nothing is more critical than security. On the off chance that you are running a business on the internet, then securing your WordPress installation ought to be at the extremely top of your necessity rundown! There is such a great amount of to say on this topic, however I have picked the absolute most expansive and effectively executable tips and plot them here. On the off chance that you are looking to enhance security, this is an extraordinary spot to begin.
Wordpress Security Tips

Get ready For A Rainy Day With Backups

Your first lesson in security ought to be realizing that the security scene is continually changing, and that you ought to never view yourself as 100% secure. Regardless of the fact that you are doing everything right, you ought to dependably have a backup plan. In the event that your website is vital to you, then you have to be performing general backups.

1. Remote Server Backups – Always store backups remotely. It’s absurd to store backups on your production server! There are some truly straightforward approaches to perform consistent backups utilizing standard server programming, for example, WHM . I would additionally propose R1soft for incremental backups.

2. Remote WordPress Backups – If a day by day full-server backup is impossible, the slightest you ought to be doing is going down your WordPress database. There are a lot of people free and paid plugins out there that can deal with this for you. I would very propose utilizing one that considers remote storage. In the event that you need to utilize FTP for file transfer, use FTPS or SFTP. Decoded FTP ought to most likely be impaired on your server in any case.

3. Utilize a Redundant RAID Array – You ought to be utilizing a have that stores your data on an excess RAID exhibit, for example, RAID 1 or RAID 10. Hard drives come up short constantly, its basically a reality of the hardware. Utilizing a RAID that mirrors your data crosswise over numerous drives will enormously lessen the danger of data loss.

Securing Your Internet Activity

Great WordPress security begins in your own particular home. Not just does your website need to be secure, however so do the systems in which you associate with it. Uniting with your server or WordPress Dashboard in an insecure way will put everything at danger.

1. Utilize A Secure Network At Home – If you are utilizing Wifi at your home or office, then I would recommend setting up a private Wpa2 network with a solid, haphazardly created name and network passphrase. For extra security, you can utilize “security through haziness” systems, for example, empowering MAC Address Filtering .

2. Utilize An Encrypted VPN Connection Over Public Wifi – Generally talking, its best to never log into a touchy zone, for example, your WordPress Dashboard when associated with the internet over open Wifi. On the off chance that you are utilizing your laptop or telephone over an open network, dependably run your association through an encoded VPN and verify that you are marking into your website over SSL. You can buy a VPN from Strongvpn.com .

Securing Your Personal Computer

Wordpress Cloud Backup

Your network is secure, however shouldn’t we think about your physical machine? It’s extraordinarily paramount to keep your workstation clean of spyware, malware and infections.

1. Infection Protection and Firewall – There is no sense in having secure passwords if your workstation could be effortlessly contaminated with malware that can get to your delicate data and spy on your internet movement. Make sure that your workstation is running trusted Anti-Virus, Firewall and Malware programming. I have had great accomplishment with Kaspersky and Malware Bytes . Both ought to be designed to automatically update and output your workstation every day.

Securing Your Online Accounts

You could be doing everything right, yet get hacked from an animal power attack in light of the fact that your password is frail. You can additionally have a solid password, yet get hacked on the grounds that you stored it insecurely.

1. Password Generation – Every login you utilize ought to have a novel, randomized password with no less than 8 characters. Your password ought to incorporate capital letters, numbers and unique characters. You can also use different Password generator tool available here .

2. Store Your Passwords Securely – If you have 20 randomized secure passwords, how would you recollect that them? In the event that you plan on storing your passwords some place that you can reference, do so in a secure way. On the off chance that you are utilizing OSX, have a go at making another Authentication keychain and make another secure note set to automatically log out following 5 minutes. In the event that you are utilizing Windows, take a stab at making a secure Onenote file set to automatically log off following 5 minutes also. You may likewise take a stab at utilizing online administrations, for example, Lastpass , or you could additionally encode your files utilizing an encryption programming, for example, Truecrypt .

3. Reset Your Passwords Regularly – Your passwords ought to be changed all the time. It’s best to set up an update on your schedule to reset the greater part of your passwords consistently or two.

Abstain from Phishing & Social Engineering Schemes


Off and on again getting hacked has nothing to do with your website or your machine, yet with your insecure correspondences. These sorts of attacks are regularly called phishing or social designing scams. The “Nigerian Prince Scam ” is the excellent case of a phishing plan.

Avoid Phishing Attempts
– Emails are major kind of phishing attacks. They frequently target expansive organizations aimlessly, for example, WordPress or Hosting organizations. A basic Whois lookup could give knowledge into your facilitating organization, and a glance at your website will uncover that you are running WordPress. A simple attack on such a website would be to stance as a worker from your facilitating organization, cautioning you about an issue with their WordPress installations and asking for your Login subtle elements so they can alter it. Don’t getbulldozed by it! No respectable organization will arbitrarily ask for your login qualifications

My First WordPress Plugin

WordPress is the largest blogging platform available on the internet today; this is my first plugins for you.

nd with the official release of version three just around the corner, it’s only going to get bigger. As such, over the next few self-contained tuts, we’re going to learn the ins and outs of WordPress plugin development, starting with the creation of our first simple plugin, “Simple Optimization.”

This tutorial is going to assume that you have at least a beginner’s understanding of PHP and the WordPress syntax. Though we’ll be covering everything, some knowledge beforehand will help you grasp the concepts much more easily. I’ll also assumes that you have a WP blog setup and ready to go.

The very first step, when writing a WP plugin, is to determine everything you want it to do. Since this is our first plugin, we won’t do anything too drastic. Let’s create something which will speed up our blog; our pages will render faster, and we’ll also do a little SEO to improve our search rank and findability.

“Always create a list of what you want your plugin to actually do before you write any code!”

  • “rsd_link” – Really Simple Discovery Link
  • “wlwmanifest_link” – Windows Live Writer link
  • “wp_generator” – WordPress version number
  • “wptexturize” – Curly quotes
  • “wp_filter_kses” – HTML in user profiles
  • Insert post tags into <head> as keywords
  • Insert post excerpt into <head> as description

To start, navigate to your plugins folder (“/wp-content/plugins/”), and create a new folder. We’ll call ours “simple-optimization.” Next, inside of this folder we’re going to need to create two files. The first will be the actual plugin file (named “main.php”), and the second will be the mandatory README (“readme.txt”). We’re going to leave readme.txt empty for the time being; so open main.php in your preferred text-editor and copy in the code below.

01
02
03
04
05
06
07
08
09
10
11
12
13
14
<?php
/*
Plugin Name: Name Of The Plugin
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
License: A "Slug" license name e.g. GPL2
.
Any other notes about the plugin go here
.
*/
?>

This text is the bare-bones minimum needed for a plugin to appear in the WordPress plugin directory. You’ll obviously need to fill each part as you see fit.

The first two features we’re going to implement will also be the simplest. By default, WordPress adds several meta-tags to the <head> section of your blog, but the simple fact of the matter is that these meta-tags have absolutely no value at all; so we’re simply going to stop WordPress from adding them. Anytime WordPress performs an action, it’s either called a filter or an action, and we can either remove or manipulate these filters and actions (you can find a list of all the filters here, and all the actions here). In this case, we want to remove the various actions that add those meta-tags.

To do so, we use a very simple function called “remove_action(‘action’,’function’)”. This function will remove the function declared in the second parameter from the action, the first parameter.

1
2
3
4
5
6
7
// Clean up wp_head
// Remove Really simple discovery link
remove_action('wp_head', 'rsd_link');
// Remove Windows Live Writer link
remove_action('wp_head', 'wlwmanifest_link');
// Remove the version number
remove_action('wp_head', 'wp_generator');

The same exact same principle applies to the two filters we’re going to remove:

1
2
3
4
5
6
// Remove curly quotes
remove_filter('the_content', 'wptexturize');
remove_filter('comment_text', 'wptexturize');
// Allow HTML in user profiles
remove_filter('pre_user_description', 'wp_filter_kses');

Now that we’ve cut out that bloat, let’s ensure our blog has some basic SEO; meaning, let’s make sure we have keywords per-page, which correspond to that page and change the description to match more with the article. For our keywords, we’re going to grab the tags of the current page/post. This is made super simple by the function“wp_get_post_tags()”. wp_get_post_tags will return an array of tags from the current post. We can then easily format this array into a string and place it within our header (inside the function “wp_head()”, that every theme should have in it already) by attaching our function to the wp_head action.

Let’s start out by creating a new function, tags_to_keywords(), and, inside of this function, we’ll write a simple if statement, which checks to see if the current page is a single post or page (using the WP functions: is_single() and is_page()). Next, we’ll create a variable inside this if statement, named $tags, and set its content to the function wp_get_post_tags(); however, in order for this function to work, we need to pass in a parameter of “post_id”. The easiest way for us to obtain that is to globalize the WP variable $post which contains the post ID ($post->ID, $post is an object which is why we’re calling its values like so).

1
2
3
4
5
6
7
8
// SEO
// add tags as keywords
function tags_to_keywords(){
global $post;
if(is_single() || is_page()){
$tags = wp_get_post_tags($post->ID);
}
}

Next, we’ll use a foreach to filter through the $tags data, and create a new array with only the information we want ($tag_array). Following that, we’ll implode the array into a string and separate each item from the array with a comma and space ($tag_string). Then, we’ll create another if statement that checks to see if $tag_string has a value (meaning, do we have any tags for the post) and if it does, echo out the final HTML.

function tags_to_keywords(){
    global $post;
    if(is_single() || is_page()){
        $tags = wp_get_post_tags($post->ID);
        foreach($tags as $tag){
            $tag_array[] = $tag->name;
        }
        $tag_string = implode(', ',$tag_array);
        if($tag_string !== ''){
            echo "<meta name='keywords' content='".$tag_string."' />rn";
        }
    }
}

The last thing we need to do now is attach our new function with the wp_head action. To do this, we’re going to call add_action(‘action’,’function’), and pass it the parameters “wp_head” and “tags_to_keywords” (in that order).

add_action('wp_head','tags_to_keywords');

To further increase our SEO, we’re going to add our description meta-data to the header as well, using the same method as the keywords. Once we have the if statement rewritten, we’re going to create a new variable $all_post_content and fill it using the WP function wp_get_single_post() (and pass the parameter of $post->ID). This will give us an object full of all the data about our post. With this variable, we can create a description using the actual content of the post, but we’re going to shorten it down to one hundred characters using the function substr ($excerpt). And then, we’ll just echo out the HTML with the excerpt written in. (Optionally, you can also add an elsestatement, and echo your blog description using the functionget_bloginfo(‘description’).)

01
02
03
04
05
06
07
08
09
10
11
12
13
// add except as description
function excerpt_to_description(){
global $post;
if(is_single() || is_page()){
$all_post_content = wp_get_single_post($post->ID);
$excerpt = substr($all_post_content->post_content, 0, 100).' [...]';
echo "<meta name='description' content='".$excerpt."' />rn";
}
else{
echo "<meta name='description' content='".get_bloginfo('description')."' />rn";
}
}
add_action('wp_head','excerpt_to_description');

The final feature for our plugin is going to optimize our database tables by removing overhead (useless/excess data in a SQL table created by manipulating the database). To begin, we’ll create a new function (optimize_database), and inside of it, we’re going to call the global WPDB variable ($wpdb). That way, we can interact with the database, without having to re-enter our authentication details. $wpdb has several methods you can use to interact with and retrieve information from the database (Full list here), but we’re only going to be using one, get_results. Using get_results with the parameters of “SHOW TABLES” and “ARRAY_A” will return to us an associative array of all the table names in the database. At that point, we can use a foreach to loop through each of the array values (using array_values to get the table name, because of how it’s layered by the function) and use another $wpdb method, query to run the optimize command (“OPTIMIZE TABLE _____”).

//Optimize Database
function optimize_database(){
    global $wpdb;
    $all_tables = $wpdb->get_results('SHOW TABLES',ARRAY_A);
    foreach ($all_tables as $tables){
        $table = array_values($tables);
        $wpdb->query("OPTIMIZE TABLE ".$table[0]);
    }
}

While this function works, it will never actually run because WordPress has no way to know to run it. Luckily, WordPress has a feature called cron, which schedules functions to run at specific intervals (daily, weekly, etc…); this is perfect for us, since we want to frequently optimize our database. To use Cron, we’re going to create a new function (simple_optimization_cron_on), and fill it with another function call towp_schedule_event(). To work, wp_schedule_event needs three things: a time to run, an interval between each run, and a function to call; so we’ll pass it the parameters: ‘time()’ (we’ll assume that whenever the cron event is created is a good time to call the function), ‘daily’, ‘optimize_database’ in that order.

function simple_optimization_cron_on(){
    wp_schedule_event(time(), 'daily', 'optimize_database');
}

Great, now we have our optimize_database function being added to the WP cron list, or we would if we were to call the simple_optimization_cron_on function. It’s really unsafe and is a bad practice to call your own event addition functions, because through some arbitrary system of events, it could cause the function to be called multiple times. WordPress happens to have a set of specific hooks for plugins to solve this problem:register_activation_hook and register_deactivation_hook. These functions are called when a plugin is turned on (activated) and turned off (deactivated). This way, our cron function can only be added once. Now, we have the ability to remove the cron event if the plugin stops being used. To work, these functions need two pieces of information: the url to the file that has the activation and deactivation functions (99% of the time “__FILE__” will work perfectly here), and the name of the activation and deactivation function. We’ll also create a new function (simple_optimization_cron_off), and fill it with a call to another function (wp_clear_scheduled_hook(‘optimize_database’)) to delete our cron event.

function simple_optimization_cron_off(){
    wp_clear_scheduled_hook('optimize_database');
}
register_activation_hook(__FILE__,'simple_optimization_cron_on');
register_deactivation_hook(__FILE__,'simple_optimization_cron_off');

The last thing we need to do for our new plugin is fill in the readme.txt file. The readme.txt file is used by the WordPress Plugin directory to display all the information you provide it about your plugin. The best way to learn how to write an effective readme.txt file is to download the default from WP, and alter it accordingly to fit your plugin. Since ours was so simplistic, this is what I personally ended up with:

=== Simple Optimization ===
Contributors: Jonathan Wolfe
Plugin link: http://net.tutsplus.com/
Tags: simple, optimization, keywords, tags, description, SEO, optimize, database
Requires at least: 2.5.1
Tested up to: 2.9.2
Stable tag: trunk

Silently adds several optimizing functions to the WordPress back-end to make your blog or site run faster.

== Description ==

Simple Optimization adds several functions to WordPress that help trim the fat from the system and also clean up after itself a little bit all leading to a faster loading time for your blog or website.

**Features**
_Remove useless meta tags:_
* "rsd_link" - Really Simple Discovery Link
* "wlwmanifest_link" - Windows Live Writer link
* "wp_generator" - WordPress version number
_Remove useless filters:_
* "wptexturize" - currly quotes
* "wp_filter_kses" - HTML in user profiles
_SEO:_
* Insert post tags into <head> as keywords
_Routinely optimize the database_


== Installation ==

1. Download, unzip and upload to your WordPress plugins directory
2. activate the plugin within you WordPress Administration
Advertisement

You just successfully wrote your first WordPress plugin, which is working and ready for the WP Plugins Directory. Along the way, you learned about filters and actions, using WP global objects, a lot about the WordPress nomencalture, how to interact with the database, cron events, and activation/deactivation hooks. If you have any questions, please leave a comment and I’ll respond as soon as I can.

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/*
Plugin Name: Simple Optimization
Description: A super-simple plugin to improve your blog
Version: 1.0
Author: Jonathan Wolfe
License: GPL2
.
This plugin written for NETTUTS at http://net.tutsplus.com
.
*/
// Clean up wp_head
// Remove Really simple discovery link
remove_action('wp_head', 'rsd_link');
// Remove Windows Live Writer link
remove_action('wp_head', 'wlwmanifest_link');
// Remove the version number
remove_action('wp_head', 'wp_generator');
// Remove curly quotes
remove_filter('the_content', 'wptexturize');
remove_filter('comment_text', 'wptexturize');
// Allow HTML in user profiles
remove_filter('pre_user_description', 'wp_filter_kses');
// SEO
// add tags as keywords
function tags_to_keywords(){
global $post; // Get access to the $post object
if(is_single() || is_page()){ // only run on posts or pages
$tags = wp_get_post_tags($post->ID); // get post tags
foreach($tags as $tag){ // loop through each tag
$tag_array[] = $tag->name; // create new array with only tag names
}
$tag_string = implode(', ',$tag_array); // convert array into comma seperated string
if($tag_string !== ''){ // it we have tags
echo "<meta name='keywords' content='".$tag_string."' />rn"; // add meta tag to <head>
}
}
}
add_action('wp_head','tags_to_keywords'); // Add tags_to_keywords to wp_head function
// add except as description
function excerpt_to_description(){
global $post; // get access to the $post object
if(is_single() || is_page()){ // only run on posts or pages
$all_post_content = wp_get_single_post($post->ID); // get all content from the post/page
$excerpt = substr($all_post_content->post_content, 0, 100).' [...]'; // get first 100 characters and append "[...]" to the end
echo "<meta name='description' content='".$excerpt."' />rn"; // add meta tag to <head>
}
else{ // only run if not a post or page
echo "<meta name='description' content='".get_bloginfo('description')."' />rn"; // add meta tag to <head>
}
}
add_action('wp_head','excerpt_to_description'); // add excerpt_to_description to wp_head function
//Optimize Database
function optimize_database(){
global $wpdb; // get access to $wpdb object
$all_tables = $wpdb->get_results('SHOW TABLES',ARRAY_A); // get all table names
foreach ($all_tables as $tables){ // loop through every table name
$table = array_values($tables); // get table name out of array
$wpdb->query("OPTIMIZE TABLE ".$table[0]); // run the optimize SQL command on the table
}
}
function simple_optimization_cron_on(){
wp_schedule_event(time(), 'daily', 'optimize_database'); // rdd optimize_database to wp cron events
}
function simple_optimization_cron_off(){
wp_clear_scheduled_hook('optimize_database'); // remove optimize_database from wp cron events
}
register_activation_hook(__FILE__,'simple_optimization_cron_on'); // run simple_optimization_cron_on at plugin activation
register_deactivation_hook(__FILE__,'simple_optimization_cron_off'); // run simple_optimization_cron_off at plugin deactivation
?>

wordpress shows post content from database

wordpress shows post content from database

query_posts command allows you to query the WordPress wp_posts database and retrieve post objects (e.g. posts, pages, attachments) based on their attributes.

get_posts is similar to query_posts and is also used to query the wp_posts database. You will note however, that the argument list it uses is slightly different compared toquery_posts, therefore make sure to refer to the WordPress codex to ensure that you are using the right argument names for each of these commands.

Both query_posts and get_posts are based on the WP_Query object. However,query_posts creates a global WP_Query object that is stored in the $wp_queryglobal variable, whereas get_posts creates a local WP_Query object that only exists within the function.

The global $wp_query variable is later used by multiple functions within the WordPress Loop. That is why it is important NOT to use query_posts within an existing WordPress Loop because it will replace the existing Loop object (contained in$wp_query) with a new WP_Query object.

query_posts is most useful when you are writing a plugin, and want to display a list of post objects within a WordPress administration menu. In the administration area, there is no Loop to worry about.

When you are operating outside of the WordPress administration area (i.e. WordPress Dashboard), it is best to use the get_posts command so that you do not inadvertently corrupt your WordPress Loop.

Incidentally, if you want to use query_posts type attributes within a WordPress Loop, then you can just create your own local WP_Query object as follows –

1
2
3
4
<?php
$tmp_query = new WP_Query;
return $tmp_query->query($atts);
?>

$atts should contain an attribute array similar to what you would use in thequery_posts function. Here are the list of parameters for query_posts.

Here is another example –

1
2
3
4
<?php
$tmp_query = new WP_Query;
$tmp_result = $tmp_query->query('category_name=aciform');
?>

How to Paginate Your query_posts Results

Sometimes, you may only want to show a certain fixed number of post objects per page, and allow users to browse through several pages of results. The code below will allow you to achieve this (partially extracted from the wp-admin/upload.phpfile).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
if (isset($_GET['paged'])) $cur_page = absint($_GET['paged']);
else $cur_page = 1;
// Get posts
$args = array(
'post_type' => 'attachment',
'posts_per_page' => 5,
'paged'=> $cur_page
);
query_posts($args);
global $wp_query;
$page_links_total = $wp_query->max_num_pages;
$page_links = paginate_links( array(
'base' => add_query_arg( 'paged', '%#%' ),
'format' => '',
'prev_text' => __('&laquo;'),
'next_text' => __('&raquo;'),
'total' => $page_links_total,
'current' => $cur_page
));
if ( $page_links ) :
?>
<div class="tablenav-pages">
<?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
number_format_i18n( ( $cur_page - 1 ) * $wp_query->query_vars['posts_per_page'] + 1 ),
number_format_i18n( min( $cur_page * $wp_query->query_vars['posts_per_page'], $wp_query->found_posts ) ),
number_format_i18n( $wp_query->found_posts ),
$page_links
); echo $page_links_text;
?>
</div>
<?php
endif;
?>

Line 2 – The current page that the user is on is set as an address line argument ($_GET[‘paged’]) by the paginate_links function (line 16). The argument name ‘paged’ is set on line 17.

Line 9 – Make sure to include this page value while calling query_posts so that you will retrieve the right set of post objects for a given page.

Line 16 -Get the proper set of links for each page. Note that the paginate_linksfunction is not dependent on any global variables (i.e. it is not dependent on $wp_query) so you can use it to generate page links for any list of objects by entering in proper values for total (total number of pages) and current (the current page).

Lines 27-35 -Display the page links returned by the paginate_links function.

 

Newsletter Subscribe

Get the Latest Posts & Articles in Your Email

We Promise Not to Send Spam:)