WordPress Database – Run MySQL Search and Replace

Once in a while, I need to move a WordPress installation from one server to another, or from root domain to a subdomain (for example – move WordPress from www.mywebsite.com to blog.mywebsite.com).

There are probably easier ways to do this, but sometimes I just like to take the hard way if it means it’s safer. The procedure is straightforward: you need to make sure you backup the database and the files, move them to the new location and replace every string in the database that contains the old address with the new address.

My process is pretty simple:

  • Download all of the files from the server through FTP.
  • Login to phpmyadmin and export the DB.
  • Upload the files to the new location.
  • Import the exported DB to the new phpmyadmin.
  • Find any traces of the old location in the DB and replace them with the new location.

How to Run a “Find and Replace” MySQL Query for WordPress’ Database

Basically we need to run the following queries for numerous tables:

  1. Postmeta
  2. Posts
  3. Options

And here are the queries:

UPDATE wp_options SET option_value = replace(option_value, 'http://the-old-domain.com', 'http://the-new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://the-old-domain.com','http://the-new-domain.com');

UPDATE wp_posts SET post_content = replace(post_content, 'http://the-old-domain.com', 'http://the-new-domain.com');

UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://the-old-domain.com', 'http://the-new-domain.com');

Copy 1 line at a time, paste in the phpmyadmin – > SQL box and click “Go”. Do this for all 4 queries.

MySQL - Find and Replace
MySQL – Find and Replace

Don’t forget to check out “Moving WordPress” and “Changing The Site URL” guides for more details about the process.

Good Luck!

How To Enable Google Analytics Demographics And Interest Reports In WordPress

If you’re running a WordPress blog, and have Google Analytics installed in order to track and analyze the traffic to your blog, you probably noticed that when you go to Google Analytics and click “Audience -> Demographics -> Age / Gender” it says that you need to validate tracking code after you have made this one-line, one-time update.

So I was trying to add this one line with my analytics plugin with no success. I also followed all of the instructions Google provides in order to make it happen.

Then, I tried to install a couple of different Google Analytics plugins for WordPress, even ones that declared they support demographics.

In the end, I succeeded in enabling it by playing around with the plugin’s code (Google Analytics for WordPress).

WordPress Demographics and Interest Reports support

Using this method, you can enable the demographics report on your WordPress blog. Please remember that since we’re going to change the plugin’s source code, every time you update the plugin, you’ll have to modify the code again, until some developer develops a decent analytics plugin to support demographics and interest reports.

Let’s begin:

1. Uninstall each and every analytics plugin from your blog.

2. Add this plugin to WordPress.

3. Activate the plugin, and go to “Settings -> Google Analytics”.

4. Authenticate the plugin with your Analytics account (just follow the instructions on the plugin’s settings page).

5. Using FTP software, go to “wp-content/plugins/google-analytics-for-wordpress/frontend/” and edit the file “class-frontend.php”.

6. Go to line 293, or search for ga.src.

7. Replace the following code:


ga.src = <!--?php if ( $this--->options['gajslocalhosting'] && !empty( $this->options['gajsurl'] ) ) {
echo "'" . $this->options['gajsurl'] . "';";
} else {
$script = 'ga.js';
if ( current_user_can( 'manage_options' ) && $this->options['debug'] )
$script = 'u/ga_debug.js';
echo "('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/" . $script . "'";
}
?>;

with the following code:

ga.src = <?php</pre>
if ( $this->options['gajslocalhosting'] && !empty( $this->options['gajsurl'] ) ) {
echo "'" . $this->options['gajsurl'] . "';";
} else {
$script = 'dc.js';
if ( current_user_can( 'manage_options' ) && $this->options['debug'] )
$script = 'u/ga_debug.js';
echo "('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/" . $script . "'";
}
?>;

8. If you have any cache plugin installed, clear the cache. Otherwise it won’t work.

9.Go back to Google Analytics -> Audience -> Demographics -> Age / Gender and click “Validate tracking code“.

10. If everything goes well, you should get this:

Google Analytics Demographics And Interest Reports In WordPress
Success!

Facebook Plugin Breaks WordPress’ Pagination

For one of the websites I created, XpatGirls.com, I installed Facebook’s official plugin for WordPress. It’s a nice plugin, that adds some “social” elements to your blog, instead of installing different plugins for different purposes, including:

  • Facebook’s Open Graph Protocol
  • Insights
  • Like, Send and follow buttons
  • Recommendation bar etc.

So, I installed the plugin on the website, like I do with almost every website that I build. A couple of weeks later, I found out that WordPress’ pagination was broken. Although the pagination appeared at the bottom of the blog, clicking on the page numbers / previous / next – would do nothing but navigate to the main page. So like everytime there’s a problem with WordPress, I started disabling themes and plugins, in order to isolate the problem, and then resolve it.

How to fix WordPress’ pagination problem caused by Facebook plugin

In the end, I found out that the Facebook plugin was the trouble maker.

To make a long story short, and to make your life easier, try adding the following piece of code to the end of the file functions.php (inside the theme’s folder). It solved my problem, and I hope it’ll solve yours.

function td_pagination_fix() {
 global $wp_query;
 unset($wp_query->queried_object);
}
add_action( 'wp', 'td_pagination_fix', 111 );

I assume it only happens with specific themes, so if you encountered this issue, please mention your theme in the comments below.

2 Step Verification for WordPress

The more popular your Blog becomes, the more vulnerable it becomes, or as they say – with great power comes great responsibility. So if your WordPress Blog enjoys heavy traffic, you have to find new and creative ways to protect it against the bad guys.

I already wrote about how to protect WordPress by limiting the number of login attempts, and as a matter of fact, since I’ve installed this plugin (2 weeks ago) in order to protect my Blog, I realized how important it is. There were 85 attempts to break into my site. Well done plugin. Well done.

So let’s say you have this plugin installed, but unfortunately someone succeeded to guess the username and password. That means you have a visitor in the admin area, and trust me – you don’t want it to happen.

So let’s add another layer of protection here, and call it 2 step verification for WordPress, using Google Authenticator.

How to enable 2 step verification for WordPress:

The Google Authenticator plugin for WordPress gives you two-factor authentication using the Google Authenticator app for Android / iPhone / Blackberry.

The process of 2 step verification is pretty simple – After typing in the right username and password, WordPress will ask you for a verification code, and you’d have to enter it on the login screen. As long as your phone with you, no one has access to your Blog (even if they have cracked the username and password). In order to enable it, follow this process:

Google Authenticator Settings
Google Authenticator Settings
  1. Go to the plugin download page, download it and install it on your Blog / Website.
  2. Install Google Authenticator on your smartphone: Android / iPhone / Blackberry.
  3. In WordPress, go to your profile (Users Menu -> Your profile) and check the “Active” option.
  4. Run the app on your Smartphone, type in your email address and the Secret code from your profile page on WordPress, or scan the QR code.

You’re done. From now on, every time you login to WordPress, you’ll have to run the Google Authenticator on your Smartphone, and type into WordPress the code provided by the app. This specific code is available only for the next 20 seconds.

8 Tips for Upgrading & Customizing WordPress’ Admin Panel

Guest post by Eliyahu Lev - Interactive Designer and WordPress Developer.
Originally published in Hebrew here.

WordPress is an easy-to-use wonderful system. I keep telling clients “If you can handle Microsoft Word, you can handle WordPress”, but we can always make WordPress better. Attached are some tips and tricks for WordPress’ Admin Panel. All of the following code snippets should be added to the file functions.php. Don’t forget to backup before you start working.

Remove admin bar

I, personally, find the admin bar pretty annoying. This is how you remove it from your website:

add_filter('show_admin_bar', '__return_false');

Change the text in the footer

By default it says “Thank you for creating with WordPress”. My suggestion is to leave it as is, and add your credit as well:


function remove_footer_admin () {
 echo "Website By <a href="http://www.yourdomain">Your name</a>";
 }
 add_filter('admin_footer_text', 'remove_footer_admin');

Remove widgets from the Home Screen

There is a lot of useless stuff here. This is how to hide it:


function tidy_dashboard(){
global $wp_meta_boxes, $current_user;
// remove incoming links info for authors or editors
if(in_array('author', $current_user->roles) || in_array('editor', $current_user->roles))
{
 unset($wp_meta_boxes['dashboard']['normal ']['core']['dashboard_incoming_links']);
}
// remove the plugins info and news feeds for everyone
 unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
 unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
 unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
//Right Now - Comments, Posts, Pages at a glance
 unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
//Recent Comments
 unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
//Incoming Links
 unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
//Plugins - Popular, New and Recently updated WordPress Plugins
 unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
//Wordpress Development Blog Feed
 unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
//Other WordPress News Feed
 unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
//Quick Press Form
 unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
//Recent Drafts List
 unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
}
//add our function to the dashboard setup hook
 add_action('wp_dashboard_setup', 'tidy_dashboard');

Add a message to the login screen

This trick is great if you want to add some custom text / message to the login screen:


function custom_login_message() {
$message = '

your message.

';
return $message;
}
add_filter('login_message', 'custom_login_message');

Remove irrelevant Menus and Sub-Menus

If you want to prevent the client from certain functions such as changing the theme, or adding / removing plugins etc., here’s an example of how to remove parts of the menu:

function remove_submenus() {global $submenu;

unset($submenu['index.php'][10]); // Removes 'Updates'.
unset($submenu['themes.php'][5]); // Removes 'Themes'.
unset($submenu['options-general.php'][15]); // Removes 'Writing'.
unset($submenu['options-general.php'][25]); // Removes 'Discussion'.
}add_action('admin_menu', 'remove_submenus');

Change the Logo on the login screen

By default, WordPress’ logo is displayed. You can change the image to your client’s logo. Pay attention to the image path “images/logo-admin.png”:


function custom_login_logo() {
 echo '</pre>
<style type="text/css"><!--
 h1 a { display:block; background-image: url('.get_bloginfo('template_director y').'/images/logo-admin.png) !important; width:330px!important; height:100px! important; background-size: 330px 100px!important; }
 
--></style>
<pre>
';
}
add_action('login_head', 'custom_login_logo');

Remove HTML editor in posts / pages

Avoid people messing with code. Don’t worry, the Admin will retain full access to the HTML editor:


add_filter( 'wp_default_editor', create_function('', 'return "tinymce";') );
add_action( 'admin_head', 'disable_html_editor_wps' );
function disable_html_editor_wps() {
 global $current_user;
 get_currentuserinfo();
 if ($current_user->user_level != 10) {
 echo '</pre>
<style type="text/css"><!--
#editor-toolbar #edButtonHTML, #quicktags {display: none;}
--></style>
<pre>
';
 }
}

Remove columns on the posts page

This snippet will help you remove select columns from the posts page, like author name, post category, tags and comments:


function my_columns_filter( $columns ) {
unset($columns['author']);
unset($columns['categories']);
unset($columns['tags']);
unset($columns['comments']);
return $columns;
}
add_filter( 'manage_edit-post_columns', 'my_columns_filter', 10, 1 );

Make WordPress faster – load images as you scroll

If you’ve ever visited Mashable, you probably noticed how fast the website loads, and you probably also noticed that images on the website appear with some fade-in as you scroll down.

This is not just to make it beautiful, although it does look great in my opinion. All it takes is a couple lines of JQuery code to make the magic happen.

If your Blog / Website is WordPress based, and is long with a lot of images, it takes some time for the browser to download and display all of the images. Basically, if the user is in the top of the page area, it makes no sense to load all of the images in the middle or the end of the page.

The solution? Use “Advanced Lazy Load” to make WordPress faster – and load images as you scroll.

Load images as you scroll

Advanced Lazy Load” is a WordPress plugin that aims to speed up WordPress. It loads images in long web pages only as the user scrolls down and approaches them.

Think about all the benefits of using this plugin:

  1. Site’s bandwidth is reduced.
  2. WordPress loads faster.
  3. Readers are happier.
  4. Site gets better ranking in terms of SEO.
  5. Images appear in a cool “fadey” way.

It works great in my blog, now it’s your blog’s turn.

How to display more than 20 posts in WordPress’ dashboard

If you’ve ever used WordPress, you’ve probably noticed that when you log in to the admin’s dashboard and display the post list, it’s limited to 20 Items (updated to version 3.7.1) per page.

WordPress is a very advanced and great blogging and content management system, and I would expect it to support showing more than 20 items (posts) per page, or at least let the user decide how many items would be displayed per page. Here’s a quick way to change it.

How to display more than 20 posts in WordPress’ dashboard:

  1. Connect to your website’s FTP, and look for the following file: /wp-admin/includes/post.php
  2. Open the file and edit it
  3. Go to line 889 (WordPress 3.7.1), or look for the following:
if ( empty( $posts_per_page ) || $posts_per_page < 1 )

$posts_per_page = 20;

4. Change the number 20 to whatever you want.

Enjoy blogging!

Top 20 Most Popular Plugins for WordPress

It doesn’t matter if you’re a dinosaur blogger, or just bought your domain and are about to launch your brand-new blog. If you’re using WordPress, you must use plugins in order to make your life easier. How much easier? Check out WordPress’ plugin library.

Plugins are tools to extend the functionality of WordPress. The core of WordPress is designed to be lean in order to maximize flexibility and minimize code bloat. Plugins offer custom functions and features so that each user can tailor their site to their specific needs.

For instructions and information on downloading, installing, upgrading, troubleshooting, and managing your WordPress Plugins, see Managing Plugins. If you want to develop your own plugin, there is a comprehensive list of resources in Plugin Resources.

Below is a list of top 20 Most Popular Plugins for WordPress. Don’t forget: before installing a plugin, make sure it’s compatible with your WordPress version. Enjoy!

1. WordPress SEO by Yoast

Improve your WordPress SEO: Write better content and have a fully optimized WordPress site using the WordPress SEO plugin by Yoast.

WordPress SEO is the most complete WordPress SEO plugin that exists today for WordPress.org users. It incorporates everything from a snippet preview and page analysis functionality that helps you optimize your pages content, images titles, meta descriptions and more to XML sitemaps, and loads of optimization options in between.

2. Jetpack by WordPress.com

Supercharge your WordPress site with powerful features previously only available to WordPress.com users.

Back in the day, there were great features available to WordPress.com users that were not available on self-hosted WordPress installs. Jetpack is a plugin that connects to WordPress.com and enables awesome features, powered by their cloud infrastructure. Some of these features use the powerful WordPress.com cloud, others are popular features provided for the convenience of not having to install and manage several separate plugin installations.

3. Akismet

Akismet checks your comments against the Akismet web service to see if they look like spam or not.

We can’t stand spam. Who can? You have better things to do with your life than deal with the underbelly of the internet. Automattic Kismet (Akismet for short) is a collaborative effort to make comment and trackback spam a non-issue and restore innocence to blogging, so you never have to worry about spam again. Akismet is brought to you by Automattic, the creators o fWordPress.com. For over 5 years, Automattic has been committed to fighting spam by continually improving the Akismet algorithm.

4. NextGEN Gallery

The most popular WordPress gallery plugin and one of the most popular plugins of all time with over 7.5 million downloads.

It provides a powerful engine for uploading and managing galleries of images, with the ability to batch upload, import meta data, add/delete/rearrange/sort images, edit thumbnails, group galleries into albums, and more. It also provides two front-end display styles (slideshows and thumbnail galleries), both of which come with a wide array of options for controlling size, style, timing, transitions, controls, lightbox effects, and more.

5. Contact Form 7

Just another contact form plugin. Simple but flexible.

Contact Form 7 can manage multiple contact forms, plus you can customize the form and the mail contents flexibly with simple markup. The form supports Ajax-powered submitting, CAPTCHA, Akismet spam filtering and so on.

6. All in One SEO Pack

WordPress SEO plugin to automatically optimize your WordPress blog for Search Engines.

7. WordPress Importer

Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file.

The WordPress Importer will import the following content from a WordPress export file:  Posts, pages and other custom post types, Comments, Custom fields and post meta, Categories, tags and terms from custom taxonomies and Authors.

8. Facebook

Add Facebook social plugins and the ability to publish new posts to a Facebook Timeline or Facebook Page. Official Facebook plugin.

The Facebook plugin for WordPress adds Facebook social plugins to your WordPress site. Associate your WordPress site with a free Facebook application identifier to enable advanced features such as automatically sharing new posts to an author’s Facebook Timeline or your site’s Facebook Page. This plugin is developed by Facebook with extra support for popular plugins and themes, custom post types, and custom post statuses.

9. Ultimate TinyMCE

Description: Beef up the WordPress TinyMCE content editor with a plethora of advanced options.

Are you a visual person? Do the letter combinations “HTML” and “CSS” send you running for the hills; but you still want to create beautiful blogs like the pros? Then this is the plugin for you! Ultimate TinyMCE will add over 40 new buttons to the default visual tinymce editor, giving you the power to visually create your pages and posts. No need for mucking about in HTML and CSS.

10. WooCommerce – excelling eCommerce

WooCommerce is a powerful, extendable eCommerce plugin that helps you sell anything. Beautifully.

Transform your WordPress website into a thorough-bred eCommerce store. Delivering enterprise-level quality and features whilst backed by a name you can trust. Say “hello” to the WooCommerce eCommerce plugin.

WooCommerce is built by the experienced folk at WooThemes who also offer premiumeCommerce themes and extensions to further enhance your shopfront.

11. Captcha

This plugin allows you to implement super security captcha form into web forms.

The Captcha plugin allows you to implement a super security captcha form into web forms. It protects your website from spam by means of math logic, easily understood by human beings. You will not have to spend your precious time on annoying attempts to understand hard-to-read words, combinations of letters or pictures that make your eyes pop up. All you need is to do one of the three basic maths actions – add, subtract and multiply. This captcha can be used for login, registration, password recovery, comments forms. There is also a premium version of the plugin, allowing compatibility with BuddyPress (Registration form, Comments form, “Create a Group” form).

12. Google XML Sitemaps

This plugin will generate a special XML sitemap which will help search engines to better index your blog.

This plugin will generate a special XML sitemap which will help search engines like Google, Bing, Yahoo and Ask.com to better index your blog. With such a sitemap, it’s much easier for the crawlers to see the complete structure of your site and retrieve it more efficiently. The plugin supports all kinds of WordPress generated pages as well as custom URLs. Additionally it notifies all major search engines every time you create a post about the new content.

13. Contact Form

Add Contact Form to your WordPress website.

The Contact Form plugin allows you to implement a feedback form to a web-page or a post in no time. It is an extremely easy form, that doesn’t require any additional settings, though there are some available options. All you need is just to activate the plugin and insert the shortcode [bestwebsoft_contact_form] into the text. There is also a premium version of the plugin with more useful features available.

14. WPtouch Mobile Plugin

Create a beautiful mobile WordPress website with just a few clicks.

WPtouch is a mobile plugin for WordPress that automatically enables a simple and elegant mobile theme for mobile visitors of your WordPress website. The mobile WordPress theme is complete with AJAX loading articles and smooth effects when viewed from popular touch mobile devices like the iPhone, iPod touch, Android mobile phones, BlackBerry OS6+ mobile devices, and more.

15. W3 Total Cache

Easy Web Performance Optimization (WPO) using caching: browser, page, object, database, minify and content delivery network support.

W3 Total Cache improves the user experience of your site by increasing server performance, reducing the download times and providing transparent content delivery network (CDN) integration. Improve the user experience for your readers without having to change WordPress, your theme, your plugins or how you produce your content.

16. UpdraftPlus – WordPress Backup and Restoration

Easy and complete backups + restoration. Manual or automated backups (Amazon S3, Dropbox, Google Drive, Rackspace, FTP, SFTP, WebDAV, email + others).

Your WordPress backups are worth the same as your entire investment in your website. The day may come when you get hacked, or your hosting company does, or they go bust – without good backups, you lose everything. UpdraftPlus simplifies backups (and restoration). Backup into the cloud (Amazon S3 (or compatible), Dropbox, Google Drive, Rackspace Cloud, DreamObjects, FTP, SFTP, SCP, WebDAV and email) and restore with a single click. Backups of files and database can have separate schedules.

17. Really Simple CAPTCHA

Really Simple CAPTCHA is a CAPTCHA module intended to be called from other plugins. It is originally created for my Contact Form 7 plugin.

Really Simple CAPTCHA does not work alone and is intended to work with other plugins. It is originally created for Contact Form 7, however, you can use it with your own plugin. Really Simple CAPTCHA does not use PHP “Sessions” for storing states, unlike many other PHP CAPTCHA solutions, but stores them as temporary files. This allows you to embed it into WordPress without worrying about conflicts.

18. Google Analytics Dashboard for WP

Google Analytics Dashboard for WP will display Google Analytics data and statistics inside your WordPress Blog.

Using a widget, Google Analytics Dashboard displays detailed info and statistics about: number of visits, number of visitors, bounce rates, organic searches, pages per visit directly on your Admin Dashboard. Authorized users can also view statistics like Views, UniqueViews and top searches, on frontend, at the end of each article. Using this plugin, your data is collected in a fast and secure manner because Google Analytics Dashboard uses OAuth2 protocol and Google Analytics API.

19. Yet Another Related Posts Plugin (YARPP)

Display a list of related entries on your site and feeds based on a unique algorithm.

Yet Another Related Posts Plugin (YARPP) gives you a list of posts and/or pages related to the current entry, introducing the reader to other relevant content on your site.

20. WP Super Cache

A very fast caching engine for WordPress that produces static html files.

This plugin generates static html files from your dynamic WordPress blog. After a html file is generated your webserver will serve that file instead of processing the comparatively heavier and more expensive WordPress PHP scripts. The static html files will be served to the vast majority of your users, but because a user’s details are displayed in the comment form after they leave a comment those requests are handled by the legacy caching engine.

WordPress editor toolbar disappeared? No problem.

The problem

So I helped someone to move his WordPress blog from one domain to another.

The process was pretty simple: Export the DB, import it into the new DB, move the files, etc. One day I’ll probably write a post about how to safely move WordPress from one domain to another, but first thing’s first.

Anyway, after moving WordPress, everything went well, except one thing: when editing a post / adding a new post, WordPress’ editor toolbar disappeared. Yes, I’ve tried everything:

  • Reset the “plugin” folder
  • Replaced the “includes” and “admin” folders
  • Deactivated every single plugin
  • Reinstalled WordPress from the update option

The solution

The solution was pretty simple. I don’t why, or how it happened, but it happened. Using Chrome’s Developer tools, I noticed an issue with the editor’s JavaScript file:

WordPress editor toolbar disappeared
WordPress editor toolbar disappeared

I logged into the blog’s FTP, and noticed there was no such file named “editor_plugin.js”. However, there was indeed a file named “editor_plugin_src.js”. I took a gamble, and changed the file name to “editor_plugin.js” – and problem solved.

How did it happen? You tell me. Actually – I don’t really care. I’m happy 🙂