Pages

Tuesday, June 25, 2013

Invalid Date Error in Google Webmaster for Sitemap generated by WordPress SEO by Yoast


If you have recently tested your sitemap that is generated by Yoast plugin for WordPress SEO, then you might have encountered an error in Google Webmaster tools while adding or testing the sitemap.

The error type would usually be mentioned as "invalid date". To fix this, one of the plugin file in Yoast SEO plugin need to be edited. Thanks to a contributor (roaming_elephant) in WordPress support forum, part of the code needs replacement. Here are the step-by-step procedures to fix this problem:

Step 1: open the plugin folder and open this php file: wordpress-seo/inc/class-sitemaps.php

Step 2: Go to line 249 and 250 where you will find the below code:
if ( $query->have_posts() )
 $date = $query->posts[0]->post_modified_gmt;
Replace the above code with the below given code:
if ( $query->have_posts() ) {
  $date = $query->posts[0]->post_modified_gmt;
  $date = date( 'c', strtotime( $date ));
}
That is all you need to do. You can now go to google webmaster tools and retest your sitemap that is generated by yoast. It should return no errors. If you have any questions, feel free to comment here.

Monday, December 31, 2012

Show more comments per page in wordpress backend

I have a very old site which I hardly bother to update. I opened the dashboard after about several months only to see that there are 653 comments. 90% of them were spam messages. Now I had to delete them or mark them as spam.

Wordpress prior to 2.8 versions used to show only 20 comments per page. But this limit is no more a limit from versions after 2.8.

If you want to increase the number of comments to be listed per page, then  follow these simple instructions:


  1. Open Comments in your wp-admin dashboard
  2. Click on the Screen Options on the right-top corner 
  3. It will open a slide-down menu.
  4. Change the number from 20 to any number that you want.
That's it. You get as many comments as you want in one page and avoid pagination process. Now you can delete, spam it or approve it in bulk very easily.

Saturday, December 29, 2012

Add Media Links in Activity Stream

Buddypress Media is a great plugin authored by rtCamp. They enable site users to upload media in albums. Media includes music, videos and photos.

However, the plugin lacks one important part - Adding media from the front end. Much like how another plugin Activity Plus does. Activity Plus lacks what BP Media provides - and that is - organizing into albums and having them stored for future use right on the members pages.

I thought of marrying both. i.e bringing BP media on the front-page where Activity Updates are posted.

//add media links

function add_media_links(){

    global $bp, $current_user;;

if (is_user_logged_in()) {

echo '<div style="float:right; font-weight:bold;">';

echo '<a href="'.$bp->root_domain . '/members/' . $current_user->user_login  .'/media/" style="color:black; padding-right:10px">Upload</a>';

echo '<a href="'.$bp->root_domain . '/members/' . $current_user->user_login  .'/albums/" style="color:black; padding-right:10px">My Albums</a>';

echo '<a href="'.$bp->root_domain . '/members/' . $current_user->user_login  .'/photos/" style="color:black; padding-right:10px">My Photos</a>';

echo '<a href="'.$bp->root_domain . '/members/' . $current_user->user_login  .'/videos/" style="color:black; padding-right:10px">My Videos</a>';

echo '<a href="'.$bp->root_domain . '/members/' . $current_user->user_login  .'/music/" style="color:black; padding-right:10px">My Music</a>';

echo '</div>';

}

else {

echo '<div style="float:right; font-weight:bold;">';

echo '<a href="'.$bp->root_domain . '/login/" style="color:black; padding-right:10px">Upload</a>';

echo '<a href="'.$bp->root_domain . '/login/" style="color:black; padding-right:10px">My Albums</a>';

echo '<a href="'.$bp->root_domain . '/login/" style="color:black; padding-right:10px">My Photos</a>';

echo '<a href="'.$bp->root_domain . '/login/" style="color:black; padding-right:10px">My Videos</a>';

echo '<a href="'.$bp->root_domain . '/login/" style="color:black; padding-right:10px">My Music</a>';

echo '</div>';}

return;

}

add_filter('bp_before_directory_activity_content',add_media_links');

?>
You may want to add this to your functions.php file.

This code, specially the last line of the code adds a filter such that whenever bp_before_directory_activity_content function is triggered, my own custom function add_media_links will trigger automatically where in, if the user is logged in, it provides direct links to the media upload as it takes $current_user->username to take them to their own page for media uploads. And if its just a visitor, these links will redirect to the login page.



You can see this in my site which is live in action at: DublinWala.Com

Thursday, November 29, 2012

Logout and Redirect to a New URL

Since Wordpress 2.7, a new template tag has been introduced using which one could redirect a logged-in user to another URL. Why would one need such a function? Well, people want logged out users to still hang-around their site to check something that might interest them.

This is how you can use this template tag:

Step 1: Add this code in your functions.php


add_filter('allowed_redirect_hosts','logout_redirect');
function logout_redirect($link)
{
    $link[] = 'example.com';
    return $link;
}
Step 2: Add this code anywhere on your site, for example in a sidebar.php or header.php or footer.php:

<a href="<?php echo wp_logout_url( 'http://example.com' ); ?>" title="Logout">Logout</a>
That's it! You are done. Wait, I just forgot to caution you that the Step 2 has PHP in it. So it won't work if you are simply adding it to a HTML text widget in sidebar or if you are adding it to a page or post. You should necessarily add this to a php file, ideally sidebar.php would do.

In case you insist that you want to use it in a sidebar widget, then better install a plugin which allows PHP in sidebar widgets. 

Monday, November 26, 2012

How to count exact number of users when BuddyPress does it wrong

There have been instances where BuddyPress function does not count active members. It is possible because they use different tables for counting. If you want to count exact members of your wordpress site then you can by-pass buddypress function. I have written a few lines of code which you can use in your functions.php file.

///count users in wp_users table and display at various places
function my_bp_core_get_active_member_count(){
 global $wpdb;
$user_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users;");
return $user_count;
}
add_filter( 'bp_core_get_active_member_count', 'my_bp_core_get_active_member_count');

What this code does is, whenever bp_core_get_active_member_count() function is triggered it routes to my custom function mentioned above and returns the users count which will be displayed across the entire site. Got it? No? then write to me!

Monday, November 19, 2012

Automatically assign a different theme randomly for every new site in Wordpress Multisite

If you are the Multisite Super Admin of your Wordpress installation, then you must have felt the need to automatically assign a different theme for every new site that gets registered.

Currently what is happening in Wordpress Multi Sites is the same default theme that you initially assign will be used by all sites - and to me that's quite boring, especially when the admins of those sites do not change the default sites. It can also be an equally boring experience if you have disabled the Themes option for your sites and thus every user gets same theme.

Here is a simple trick from your wordpress kid:

  •  Step 1: Open wp-config.php file 
    • I'm sure you would know how to open this file. For those who don't please go to control panel of your hosting service provider where you can find the wordpress installation files. You wil find wp-config.php right in the root directory of your site.
  • Step 2: Just before the line which says "*/ That's all, stop editing! Happy blogging. */" paste this following code:
    • $theme1 =  'surface'; //theme1 folder name
       $theme2 = 'colorway'; //theme2 folder name
       $theme3 = 'amdhas'; //theme3 folder name
       $theme4 = 'swedish-grays'; //theme4 folder name
      
       $array = array($theme1, $theme2, $theme3, $theme4);
       $random_theme = $array[rand(0, count($array) - 1)];
      
       define('WP_DEFAULT_THEME', $random_theme);
  • Note that your theme folder names should be included in the variables $theme1, $theme2 etc. They are not theme names, but they are the folder names containing your themes. You can get these folder names in the wp-content/themes folder
  • Step 3: Sit back, take rest because you're done
    • The above code does the trick of assigning a random theme for every new user. 
If you face any difficulties, you could simple comment here and I will try to respond. That's two cents from Wordpress Kid. Thanks for reading. 

Monday, November 5, 2012

How to unlock Wordpress Admin when Theme My Login locks you up

The other day, I got myself into trouble when I forgot my admin password (silly me!) Well, I am a wordpress kid so I deserve the right to commit such silly mistakes. I knew that it got locked because of the Theme-My-Login plugin. But I didnt know how to unlock it.

To unlock my admin login, I kept moving from pillar to post in search of a trick. Some said there was no solution and some dared to give a trick (like change the plugin name). Somehow none worked for me.

I thought I should do something myself and did these following steps and it worked. Here are the steps you may want to use in case you got locked up by Theme My Login plugin.


  • Step 1: Try to find your way straight to your database itself.
    • If you are using cpanel, then the click on PhpMyAdmin where you actually find your wordpress installed database and its related tables. 
  • Step 2: Try to find wp_usermeta table and open the table
    • Opening wp_usermeta table is quite easy in PhpMyAdmin. All you need to do is click on your database on the left panel and a list of tables will be presented. From this you can easily click on wp_usermeta table.
  • Step 3: Try to find the row having meta_key as "theme_my_login_security"
    • You can find this in the same table under meta_key column. If there are too many rows and you are finding it difficult to find this meta_key, then you can write a SQL query in the SQL Query option on the top menu. The query could be like this:
      • SELECT * 
        FROM `wp_usermeta` 
        WHERE `user_id` =1
        AND `meta_key` = 'theme_my_login_security'
        LIMIT 0 , 30
  • Step 4: Delete that row having theme_my_login_security as meta_key
    • Deleting is a fairly easy task on PhpMyAdmin. Simply click on Delete link corresponding to the row having theme_my_login_security as meta_key. 
  • Step 5: Take a deep breathe and Login from a new browser.
    • Success, isn't it? If not then send me all your brickbats along with the specific detail of your problem. This kid of wordpress can try to help you in such a case. 
Hope this trick is useful for you.