If you have ever wondered how to get the user id from user login name in wordpress, here is the answer. By using get_userdatabylogin $user = get_userdatabylogin(’loginname’); if($user){ echo $user->ID; }
Dynamic WordPress URL
If you have more than one domains (addon domains) for the same wordpress site you can add the following to your wp-config.php to override the default WP_HOME and WP_SITEURL definitions with dynamic host address. Adding these two definitions also reduces the number of database queries and thus improves site performance. Here is an example (note [...]
Changing the site url in WordPress
If you move your wordpress installation to a new location (a new domain or another folder), you need to change all urls within your wp database. You might find some plugins to do this task but in my opinion the easiest way to do this is by using phpMyAdmin. Just run the following SQL Statements [...]
Allow iframe in WordPress Posts
If you’ve ever tried adding an iframe to your WordPress post, and then switched the TinyMCE editor to Visual mode, you’ve found that the editor strips out your iframe code. This can be annoying. Just add this snippet to the functions.php file in your theme folder to prevent TinyMCE from killing your iframe. function [...]
Disable and Remove WordPress Revision Post Features
After WordPress introducing post revision features, it helps wordpress blogger to keep revision of post and restore to previous revisions anytime. However, too many revision stored on wordpress database might cause longer query time and processes database requests. That means, your blog will load slower and your visitors may wait longer before the content comes [...]
Adding a localization menu to WordPress
First an explanation of how localisation works. WordPress provides a localisation in the form of .mo files. These are like mini dictionaries, and allow WordPress to reference a translation by an English phrase. These files are downloaded from the WordPress localisation repository and are then installed into the /wp-includes/languages directory (you may need to create [...]
Using shortcodes everywhere
By default shortcodes are only processed in post/page content. However you can use them in many other places, you only have to enable them for each field you want. Here’s a little tutorial of how to use shortcodes in widgets, excerpts, comments, theme files, user descriptions, and category/tag/taxonomy descriptions.
Check if a WordPress plugin is active
If you want to check if a WordPress plugin is active, just use the is_plugin_active() function. The function takes a single parameter, which is the path to the plugin, as shown in the example below:
Showing custom post types on your home/blog page
By default, WordPress shows only the “post” post type on your home/blog page. If you want to display your custom post types you have to add a filter (pre_get_posts). So let’s suppose we have created the post types “portfolio and gallery” in addition. To add these, open your theme’s functions.php file and paste the following [...]