Categories
Make Money Online My Personal Reviews WordPress How To

WordPress: Display Ads in Post Content and Only Display Ads in Old Posts

The title pretty much says it all. It’s 2 of the most useful AdSense ads tips for bloggers in my opinion. Obtrusive ads have the unnecessary effect of driving away readers after they have found what they needed. Unless you have amazingly great content, the chance of them becoming a loyal reader is rather low when you have ads splashing into their faces – this is not something you want to do to your subscribed readers. On the other hand, you’d want to maximize your AdSense earnings by putting up ads on as many posts as possible.

Ad Injection (WP plugin)

This tiny little plugin, Ad Injection, gets it all. Very useful plugin for you to insert AdSense ads in your blog posts AND set a specific age threshold for the posts to display ads, so freshly published articles won’t have ads to drive your subscribers away. See detailed introduction here: Ad Injection for WordPress.

Just install it from the inventory (upload or install from within your WP administrator panel) and activate it. Go to Settings > Ad Injection > “Random ad (inserted randomly between paragraphs)” and insert your AdSense code there. Depending on how aggressive you are, you can use a variety of ad formats from Google. I used a 468×15 links banner on Health Not. Check out the screenshot below:

insert ads in wordpress posts

By default, Ad Injection inserts a maximum of 2 instances of the Random ad per post. This way, the ads are well blended in the content. What works a few years back with the 336 square ad format on top of the content is gradually dying out in CTR thus click revenues. You should try something new such as this.

Another useful option of the plugin is to set “Only show normal ads on pages older than xx (days) – only for single posts and pages”. This would prove very useful if you want a good balance between ad performance / earnings and user experiences. Only displaying ads on older posts are a pretty good idea for creating a good first impression to those who stumble upon your site.

Categories
WordPress How To

Customize WordPress Post Editor CSS Styles

Do you know you can actually change the CSS styles of the entire editing area / editor where you create the post content in WordPress? It doesn’t have to be the default styles and since version 3.0, people can freely style the TinyMCE rich text editor shipped with WordPress however they want to by a few simple changes to the theme files.

Step 1

Open the functions.php file in your theme folder (create it if it doesn’t exist) and add this line anywhere in the PHP tags <?php … ?>:

add_editor_style();

Step 2

Create a css file named editor-style.css and put it in the theme root, namely the same folder where functions.php is in. To start with, you may want to copy the CSS styles from that of the Twenty Eleven theme into yours.

Now you can freely change those styles (such as rich text font, size or color, etc.) to have your own customized WordPress editor styles. The default editor styles coming with Twenty Eleven are very nice that make me long to write. So I’m now using them for my editor in the current theme, Thesis. You should too, if you find it more inspiring than the default styles.

Categories
CSS & HTML Tips HTTP Tips & Tutorials PHP Tips & Tutorials WordPress How To

Redirect 404 Error to Home Page

Other than making your 404 error page user friendly, you can redirect it to your index pages such as the homepage, sitemap, or search page, to make it useful for the users. Instead of relying on them to correct the error themselves, you offer the new orientation.

How to redirect a 404 error page to the home page?

There are essentially 3 ways to do this depending on the technology your site is built on.

The .htaccess and HTML solution

This works across all sites that are served by the Apache web server with .htaccess enabled. Add this line in the .htaccess file in the root directory of your domain:

ErrorDocument 404 /404.html

And in 404.html, add a meta tag in the HTML head section:

<meta http-equiv="Refresh" content="1; URL=http://www.example.com/">

So when there’s an 404 Not Found error the user would be first redirected to /404.html and in turn, he or she would be redirected to the homepage http://www.example.com/ (or whatever you change it to) by the meta Refresh actions.

The PHP solution

If you are using PHP to code your site, chances are you know this solution. You can always use the previous solution (The .htaccess and HTML solution) to redirect 404 error page to your home page on a PHP site, but you can also try the pure PHP approach instead.

Whenever a user types in a URL request that you do not recognize, render this:

header("HTTP/1.1 404 Not Found");
header("Location: /");
exit();

Which would redirect the user who has hit a 404 error to the homepage / or any other page URL you specify there.

The WordPress solution

If you are using WordPress for your site, make a 404.php file in your theme directory with the following content:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));
exit();

WordPress would automatically use 404.php as the default 404 Not Found error page and when a user hits that page, he or she would then be taken to the home page your WordPress blog.

Categories
Business and Marketing My Personal Reviews WordPress How To

Thesis Theme Review – Don’t just create good products but irresistable ones.

Merely good product is far from enough. To rake in profits in the magnitude vast majority of us can only dream of, you need an irresistible product – just like Thesis Theme. Think of something you’ve purchased that’s been insanely useful, beautiful and user friendly and then double it.

iPhone has proved it all. It converts massive numbers of mobile users and introduces a grand new era of mobile computing. The best part is that it easily compels all the users who now desire more to put everything Apple releases in future on their must-buy list. I can’t think of anything else in the IT world in the past decades that has come up even close. The products have not been released nor announced yet. However, that’s the kind of appeal irresistible products create.

Categories
WordPress How To

WordPress blog goes blank after editing and updating the theme files

Really weird but not unexpected at all. After trying to edit and update a theme file functions.php to override a native function of WordPress, get_search_form, inserting these lines at the end of functions.php of my theme:

function get_search_form() {
?>test<?php
}

To see if the native get_search_form() function can be overriden. Turns out it can’t. Not only that but my WordPress blog refuses to load anything other than a blank white page. I have to get on FTP to revert those changes.

And it recovers from the strike.

Categories
Free WordPress Themes WordPress How To

Best Damn Premium WordPress Theme for Professional Blogs: THESIS

Best and most powerful premium wordpress theme for professional blogging Imagine the best WordPress theme you have ever used and then triple the pleasure you enjoyed with it – that’s what Thesis can give you.

Whatever your niche is, if you are ever after a powerful, beautiful WordPress premium theme well balanced between functionality and customizability with best support from the author, this is the deal.

Epic WordPress Theme for Heroic Bloggers

Let’s sum up a list of what an epic WordPress theme should accomplish:

  1. The design – of course, what more can we expect from a theme than the exterior beauty itself. If simplicity is the ultimate aesthetic sophistication, Thesis is the ultimate simplicity.
  2. The functionThesis has all the built-in functions and little gimmicks you have seen across all WordPress themes combined. No more nor less, they are just what you need when you need them.
  3. The code – Forget it, you won’t need a single touch of the theme code to make any customization any more. Thesis comes with its own full-fledged magic panel that’s so powerful and so intuitive to use, your blog instantly becomes WordPress 4.0 while the rest are still using the newly released WP 2.8.
  4. The support – Every theme buyer / owner will have his or her own login details at the official site to access the control panel and support desk as well as tools to resell the theme to their clients at a much discounted price.
  5. The audience – As undoubtedly the One WordPress Theme, Thesis has been adopted by hundreds of pioneer bloggers that are admired by tens of millions of readers and visitors per month. Looking for more?
  6. WordPress 2.8? – No, it’s WordPress Thesis.

I’m personally a user of Thesis and have been extremely happy with it on a bunch of my blogs: Virtual Assistants, Database Press and Induction Heaters.

Categories
Domains SQL / MySQL Tips and Tutorials WordPress How To

How to Transfer / Move WordPress Blog from One Domain to Another

Basically, the root URL of your blog which is your domain or subdomain is changing here. Though this doesn’t seem like a sane decision considering the huge SEO impact that might fall upon your site but with HTTP 301 permanent redirection, this can still make sense in some situations.

Assume you won’t change the details of the WordPress database connection, then there’d be no need to change or modify any PHP files at all. Just the database tables and related values concerning the URLs.

The idea is to find all table field values containing the string ‘olddomain.com‘ which is your old domain and change it to the new domain ‘newdomain.com‘. Follow me:

  1. Copy all the WordPress PHP program files from the old directory to the new one which the new domain is pointed at.
  2. Connect to WordPress database by phpMyAdmin or plain mysql command or whatever you are familiar with. But this example will only go with phpMyAdmin.
  3. In phpMyAdmin, at the database level, click ‘Search‘ -> ‘Select All‘ -> Search for ‘olddomain.com‘ -> Click ‘Go‘. In most cases, there are just 2 tables that need to be modified accordingly: wp_posts and wp_options.
  4. Click ‘Browse’ to look for records with the string ‘olddomain.com‘ in them.
  5. For ‘wp_options’, edit each record and find all occurrences of the old string ‘olddomain.com‘ and modify it to ‘newdomain.com‘. Click ‘Go‘ to update.
  6. For ‘wp_posts’, you can leave the guid field intact or update it with the new domain string but it doesn’t matter much. The hard part is to update the post content of all posts and replace all occurrences of the old domain string to the new one. You can get all this done by the following SQL query: UPDATE wp_posts SET post_content = REPLACE(post_content, 'olddomain.com', 'newdomain.com')

Now you should be set, fire up your browser and navigate to your blog at the new domain and check everything out to see if it’s working properly.

Categories
SQL / MySQL Tips and Tutorials WordPress How To

MySQL: String Function to Replace Substring and Change Part of the Field Value

A typical case of replacing a part of the string to another substring in a database table is switching between site domains or URLs, such as when you want to transfer your WordPress blog from one domain to another. You have to change all values containing the original site URL to the new one in the wp_options and wp_posts table.

For example, when you transfer from olddomain.com to newdomain.com, you will better perform the following SQL query in the wordpress table wp_posts:

UPDATE wp_posts SET guid = REPLACE(guid, 'olddomain.com', 'newdomain.com')

And the MySQL function REPLACE() makes sure all substrings ‘olddomain.com’ in the value of the guid field will be replaced by ‘newdomain.com’.

Categories
Hilariously Funny or Creepy WordPress How To

WordPress: 503 Service Temporarily Unavailable when Posting New Posts or Modifying Existing Posts

It’s weird that I encountered this problem that when you post new posts in WordPress, there’s a possibility that it may run into a 503 Service Temporarily Unavailable error without publishing the article at all.

I did some split tests and in this post, the string ‘fopen’ which is a php function seems to be the culprit that prevents the post being posted, constantly causing the wordpress to make 503 service temporarily unavailable errors when you hit Publish or Update.

One workaround is to do the split tests on your posts and see which part of it is causing the problem so that you can change it to something else until WordPress accepts.

Haven’t notified the wordpress team yet, don’t know if they have received other complaints about this bug (or is it) or not, I think I’m just too lazy to send the report. Whatever… as long as you can get things done, doesn’t really matter if there’s a glitch.

Problem Solved

Update: Turns out this error is not alone in WordPress and not a bug of it at all. Some of the administration tasks of other CMS software such as posting posts with PHP code in them and uploading stuff would also trigger a module in Apache called Mod_security to be over sensitive. The solution is to disable the module (not recommended), or put a simple line into the .htaccess file of the site to tell Mod_security that:

  1. All requests from this particular IP address is absolved from being inspected and monitored by Mod_security module –
    SetEnvIfNoCase Remote_Addr ^123\.123\.123\.123$ MODSEC_ENABLE=Off
  2. All requests made to this specific PHP script is absolved of being checked for malicious attempts –
    SetEnvIfNoCase Request_URI ^/wp-admin/async-upload\.php$ MODSEC_ENABLE=Off

With WordPress, the potentially problematic scripts I know include:

  1. /wp-admin/async-upload.php
  2. /wp-admin/post.php
  3. /xmlrpc.php

So depending on the error you are getting from the task you are performing, insert one or two lines into the .htaccess to prevent any unnecessary 503 errors. Read more about this issue at DreamHost wiki.

Categories
PHP Tips & Tutorials Regular Expression Tips & Tutorials WordPress How To

PHP: Generating Summary Abstract from A Text or HTML String, Limiting by Words or Sentences

On index or transitional pages, such as homepage or category pages of WordPress, you don’t want to show the full texts of your deep content pages yet but just a content snippet of the first few sentences or words as a summary with a read more link to the actual article.

This is generally good in terms of SEO as it reduces duplicate content on your site and increases page views. With WordPress you can simply achieve this by using a plugin named Evermore. However, with a home made CMS to select and display content abstracts, you will have to code a little bit on your own.

While you may be better off doing this with a plain SQL which I’m not an expert in, I’ll let in a little trick of PHP to accomplish the same task here.

Full HTML Text
$text = <<<TEXT    
I wrote a <a href="#">blog post</a> yesterday about Chinese web design fonts. What did you think? It appeared that many are very interested. I guess it's the language barriers and cultural differences that make the westerners eager to know more about us. All right then, let me write more about that and maybe start a <strong>brand new domain</strong> for it. Stay tuned!
TEXT;
The Problem – select first sentences

Select and display the first 3 sentences (max) of the full HTML text above.

The Solution
<?php
preg_match('/^([^.!?]*[\.!?]+){0,3}/', strip_tags($text), $abstract);
echo $abstract[0];
?>

Output:

I wrote a blog post yesterday about Chinese web design fonts. What did you think? It appeared that many are very interested.

Stripping out HTML tags for the summary is to prevent it from producing invalid HTML snippets as it’s possible that the process slices HTML elements in half, leaving just part of the tag or only the beginning tag there. However, you can always preserve tags in the abstract, with a slightly more sophisticated algorithm of course.

Another Problem – select first words

You want to distill an abstract of the first 30 words instead of sentences concluded by period punctuations such as ‘.’, ‘!’ and ‘?’.

The Solution

Simply modify the regular expression to:

/^([^.!?\s]*[\.!?\s]+){0,30}/

Output:

I wrote a blog post yesterday about Chinese web design fonts. What did you think? It appeared that many are very interested. I guess it's the language barriers and cultural

There’s an incomplete sentence so you may want to add a trailing of ‘…’ at the end to denote the abstract nature.

In regular expressions, \s stands for all sorts of white spaces including single-byte space, tab and new line.