Showing posts with label WordPress. Show all posts
Showing posts with label WordPress. Show all posts

Tuesday, May 15, 2012

WordPress: Set All Posts to Draft

The following sql code snippet will set all posts/entries in WordPress as draft.

UPDATE wp_posts
SET wp_posts.post_status = 'draft'
WHERE wp_posts.post_type ='post';

Sunday, November 21, 2010

Disable the admin bar in WordPress 3.1

One of the new features in WordPress 3.1 is the Admin Bar. It will automatically on by default.

To disable the admin bar, append the following code into functions.php file.
 /* Disable the Admin Bar. */  
 remove_action( 'init', 'wp_admin_bar_init' );  
The functions.php file is located inside the theme directory. You need to create one, if it does not exists yet.

Sunday, July 25, 2010

WordPress: Add Facebook Like Button using functions.php

The Facebook Like button lets a user share contents with friends on Facebook. When the user clicks the Facebook Like button, a story appears in the user's friends' News Feed, with a link back to the original website.

[caption id="" align="alignnone" caption="Facebook Like Button"][/caption]

Append this code snippet to functions.php file in theme or child theme folder to add the Facebook Like Button.
function add_fb($content) {
$fb = ''; // display only on single page.
if (is_single()) {
$fb = '<iframe src="';
$fb .= urlencode(get_permalink(get_the_ID()));
$fb .= '&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;';
$fb .= 'action=like&amp;colorscheme=light"';
$fb .= ' style="border:none; overflow:hidden; width:450px; ';
$fb .= 'height:60px"></iframe>';

// display before the content.
return $fb . $content;

// display after the content.
// return $content . $fb;

add_filter('the_content', 'add_fb');

Please visit for more information on how to customize the Like Button.

Friday, January 22, 2010

How to create word cloud for free

Word cloud also known as tag cloud is a generated tags based on the words of a web site. In other words, we can say that it is a visual picture of a web site.

Wordle is a free web application to create word cloud. It has the capability to create word cloud from a bunch of pasted text, from a blog or web site with Atom or RSS feed enabled, and from user tags.
Word cloud created with Wordle
According to Wordle, word cloud created with Wordle can be used for anything, even if you are making profit of it, as long as the credit goes back to Images created by the web application are licensed under a Creative Commons Attribution 3.0 United States License. Examples of usage include book cover, t-shirt or even as blog header like the one used by WordPress Foundation blog, which was made public today. Read WordPress Foundation first article.

What is your opinion about word cloud? Is it a good way to describe your blog? Please leave your comment.

Sunday, January 3, 2010

How to disable shortlink

WordPress 2.9 provides shortlink for each post for free. However, if you don't like it, you can disable it easily.

To disable it, copy and paste the following code into your theme's functions.php file.
/* Disable Auto Adding of Shortlink */
remove_action('wp_head', 'shortlink_wp_head');

Sunday, December 6, 2009

Google Analytics new asynchronous tracking code

Google Analytics has now provides new asynchronous tracking code. The main feature of the asynchronous code is that it could load ga.js while the page is being rendered.

There are two ways to use this code.

  1. Place the code below before the  </head> tag.
     <script type="text/javascript">  
     var _gaq = _gaq || [];  
     _gaq.push(['_setAccount', 'UA-XXXXX-X']);  
     (function() {  
       var ga = document.createElement('script');  
       ga.src = ('https:' == document.location.protocol  
         ? 'https://ssl' : 'http://www')  
         + '';  
       ga.setAttribute('async', 'true');  

  2. Split the code. Half of the code will be put before the </head> tag. Another half will be put at the end of the page, before the </body> tag.
    The first half (before </head> the tag).
     <script type="text/javascript">  
     var _gaq = _gaq || [];  
     _gaq.push(['_setAccount', 'UA-XXXXX-X']);  
    The second half (before </body> the tag).
     <script type="text/javascript">  
     (function() {  
       var ga = document.createElement('script');  
       ga.src = ('https:' == document.location.protocol  
         ? 'https://ssl' : 'http://www')  
         + '';  
       ga.setAttribute('async', 'true');  


  1. Remove any existing Google Analytics code before using this asynchronous code.

  2. Disable any Google Analytics plugin (if you use one) for WordPress.

  3. Replace UA-XXXXX-X with your web property ID.

Friday, November 20, 2009

Enable Mod Rewrite on WAMPSERVER

You need to enable Mod Rewrite in order to use pretty permalinks in WordPress or Clean URLs in Drupal.

However, WAMPSERVER does not enable Mod Rewrite by default.

To enable Mod Rewrite,
  1. Click on the WAMPSERVER icon in the system tray, and choose Apache.
  2. Click on Apache modules.
  3. Click on the down triangle until you see rewrite_module. Click to enable it.
  4. Restart All Services.
Figure 1 shows the steps graphically.

Figure 1: Steps to enable Rewrite Module on WAMPSERVER 

Thursday, November 19, 2009

How to use CSS to style code snippets

It is easy to use CSS to style code snippets, as shown in Figure 1.

[caption id="attachment_2836" align="alignnone" caption="Figure 1: Sample output of CSS style for code snippets"]Figure 1: Sample output of CSS style for code snippets[/caption]

Step 1: Append this code inside a style sheet.

pre{ font-size:12px; background:#fff; border:1px solid #000; line-height:20px; width:600px; overflow:auto; overflow-y:hidden; margin:0; padding:0; } pre code{ font-family:Monaco,Courier; display:block; margin:0 0 0 40px; padding:18px 0; } 

Step 2: Put the code snippets inside <pre> and <code> tags.

<pre><code>def f(): txt = "Some sample code" return txt </code></pre>

Tuesday, August 18, 2009

How to post source code for viewing in allow you to post source code of some languages.

The supported languages include:

  • bash

  • cpp

  • csharp

  • css

  • delphi

  • html

  • java

  • jscript

  • php

  • python

  • ruby

  • shell

  • sql

  • vb

  • xml

What you need to do is to wrap the source code between sourcecode tag. For example:
[sourcecode language='python']

your code here


Friday, July 10, 2009

WordPress: Display only on first page

This code will enable you to display items such as text or image only on the first page of the homepage or archive.

It can be use in index.php, category.php or archive.php.

What you need is the $page WordPress variable. 1 for the first page of results, 2 for the second page, etc.

To use it, put the code inside The Loop.
<?php if ( $paged < 2 ) { ?>

Your text or image for the first page goes here!

<?php } else { ?>

WordPress 2.8.1 is avalaible for download

According to the WordPress blog, WordPress 2.8.1 is now ready for download. Version 2.8.1 includes updates and security patches for version 2.8 bugs. One of the most important update is the reduce of memory usage of the Dashboard.

Click here to download the latest WordPress release.

Monday, June 8, 2009

WordPress 2.8 is now RC1

WordPress version 2.8 Release Candidate 1 has been released.

You can download it here.

For more information, click here, or you can click here for the changelog.

Sunday, May 24, 2009

WordPress 2.8 now in beta 2

WordPress 2.8 development is now in beta 2.

Click here to download.

For more information, click here.

Disable automatic feed links in header for WordPress 2.8

WordPress 2.8 provides a new function, automatic_feed_links().

This function will enables the automatic output of feed links, including the comment feed in the header area of the document.

To disable this feature, paste this code in function.php file.

Sunday, May 17, 2009

WordPress 2.8 new Theme Installer routines

WordPress finally includes theme installer in version 2.8.


Therefore, we can now  browse and install new theme from the dashboard.


There is also a function to upload theme.


Click here to download WordPress 2.8 Beta 1

Thursday, May 14, 2009

Create horizontal categories menu in WordPress without CSS

To create a horizontal categories menu separated by ' | ' in WordPress, use this code.
echo str_replace('<br />',' | ',

Wednesday, May 13, 2009

How to display the number of comments in WordPress

To display the total number of comments, Trackbacks, and Pingbacks for a post, use comments_popup_link or comments_number tags.

These tag must be within The Loop.

In index.php or archive.php

Use comments_popup_link. Will not work if in a page or single post.
<?php comments_popup_link('No Comments', '1 Comment', '% Comments');  ?>

In single.php or page.php

Use comments_number.
<?php comments_number('No Comments', 'One Comment', '% Comments');  ?>

Align right WordPress avatar image in comments

Paste this code inside style.css file, to align right the avatar image in WordPress.
img.avatar { float:right; margin:0 0 0 10px; padding:3px; }

Thursday, April 30, 2009

Remove WordPress generator

To remove WordPress generator, append this code to function.php:

Method 1:

This method will not work on WordPress 2.8.
function remove_generator()
    return '';

Mehod 2:

This method will work on WordPress 2.8.
<?php remove_action('wp_head', 'wp_generator'); ?>

Sunday, April 26, 2009

Show all posts in a category in the Archives page

Dump this code in the Archives template before the loop.
global $wp_query;
    array('showposts' => -1),