WordPress: Change Allowed Comments Html Tags [ allowed_tags() ]

Your blog readers can post comments with the html tags. You can display a list of all allowed HTML tags in the comments form using the following php code. Open comments.php (located in your themes directory) file and append the following code either before the comment form or submit button html code (please note that some themes have the following code, but it is usually commented out).

Your blog readers can post comments with the html tags. You can display a list of all allowed HTML tags in the comments form using the following php code. Open comments.php (located in your themes directory) file and append the following code either before the comment form or submit button html code (please note that some themes have the following code, but it is usually commented out).
Continue reading “WordPress: Change Allowed Comments Html Tags [ allowed_tags() ]”

WordPress Disable RSS Feed

Explains how to disable Wordpress RSS / Atom / RSS2 feed url in 2 simple steps.

Some webmasters and small business owners use WordPress as CMS. They may not need any sort of RSS feed. This is also good for security and private space blogs. You can easily disable all RSS feed by editing functions.php file. This file used to change the default behaviors of WordPress. It goes in your Theme’s folder. A Child Theme can have its own functions.php.

The functions file behaves like a WordPress Plugin, adding features and functionality to a WordPress site. You can use it to call functions, both PHP and built-in WordPress, and to define your own functions. You can produce the same results by adding code to a WordPress Plugin or through the WordPress Theme functions file.

How do I edit functions.php?

Click on Appearance > Themes > Theme Editor > Locate and edit your functions.php. Beware: if you do not edit file properly the results can be unexpected — even site-disabling. Make a backup of your exisiting file using ftp / sftp.

Fig.01: WordPress Themes Editor
Fig.01: WordPress Themes Editor

Make sure you add the following code between <?php ?> tags.

/**
 * Disable Our Feed Urls
 */
function disable_our_feeds() {
	wp_die( __('<strong>Error:</strong> No RSS Feed Available, Please visit our <a href="'. get_bloginfo('url') .'">homepage</a>.') );
}
 
add_action('do_feed', 'disable_our_feeds', 1);
add_action('do_feed_rdf', 'disable_our_feeds', 1);
add_action('do_feed_rss', 'disable_our_feeds', 1);
add_action('do_feed_rss2', 'disable_our_feeds', 1);
add_action('do_feed_atom', 'disable_our_feeds', 1);

Save and close the file.

How to: Set WordPress Blog on Your Home Page While Leaving Admin Files in Subdirectory

You can easily set wordpress blog hosted in a subdirectory as a homepage. Let us assume that your blog is hosted at domain.com/blog/. To set home page for domain.com, create index.php in root directory and append the following code (note blog is hosted in /blog/ subdirectory):

<?php
/* Short and sweet */
define('WP_USE_THEMES', true);
define('WP_IN_ROOTDIR', true);
require('./blog/wp-blog-header.php');
?>

Now if anyone visit domain.com, they will see blog home page w/o visiting domain.com/blog.

This way you can give out WordPress its own directory while leaving blog in the root directory. You can find more information here.

How to: WordPress Count Words in a Post

Here is sample code I use to count words in a post ( I found it somewhere while searching something else). Put the code in functions.php (no need to write plugin)

function blog_post_wordcount() {
        global $page, $pages;
        if ( !function_exists('str_word_count') ) {
                return str_word_count(strip_tags($pages[$page-1]));
        } else {
                return count(explode(" ",strip_tags($pages[$page-1])));
        }
}

You can call blog_post_wordcount() from template. Following code will display ad only if a post has more than 100 words:

$words=blog_post_wordcount();
if ( $words >= 100 ) { show_ad(): }

Combine Two WordPress RSS feed into a single Feed

If you have two blogs installed on same domain, you may want to combine two blogs feed into one blog feed. It will provide few benefits:

a) Ease of feed management

b) More readers

c) Better feed stats and much more

Required tools

=> MagpieRSS rss parser for php (download link)

=> FeedCreator lets you easily create RSS 0.91, 1.0 or 2.0, ATOM 0.3 and OPML 1.0 feeds with PHP (download link).

Download required tools

Download required tools to your desktop and upload to your server in myfeed directory using ftp / sftp client. Following instructions assumes that you have a shell access to server:
mkdir myfeed
cd myfeed
wget http://internap.dl.sourceforge.net/sourceforge/magpierss/magpierss-0.72.tar.gz
tar -zxvf magpierss-0.72.tar.gz
cp magpierss-0.72/*.inc .
mv magpierss-0.72/extlib/ .
rm -rf magpierss-0.72*
wget http://www.bitfolge.de/download/feedcreator_172.zip
unzip feedcreator_172.zip
rm *.zip *.txt

Create rss.php script

Now you have all required tools, just create rss.php script :

<?php
$TMP_ROOT = "/tmp";
$DOMAIN_NAME = "http://theos.in/";
$SITE_TITLE = "Your Site / blog Title";
$SITE_DESRIPTION = "Your Site / blog Description";
$SITE_AUTHOR = "Vivek";
$SITE_LOG_URL = $DOMAIN_NAME."logo.jpg";
$RSS_DIR = "/home/lighttpd/theos.in/http";
 
define('MAGPIE_DIR', $RSS_DIR.'/myfeed/');
define('MAGPIE_CACHE_DIR', $TMP_ROOT.'/rsscache');
 
/* include required files */
@require_once(MAGPIE_DIR.'rss_fetch.inc');
@include(MAGPIE_DIR.'feedcreator.class.php');
 
/* Set RSS properties */
$rss = new UniversalFeedCreator();
$rss->useCached();
$rss->title = $SITE_TITLE;
$rss->description = $SITE_DESRIPTION;
$rss->link = $DOMAIN_NAME;
$rss->syndicationURL = $DOMAIN_NAME."/rss/rss.php";
 
/* Set Image properties */
$image = new FeedImage();
$image->title = $SITE_TITLE. " Logo";
$image->url = $SITE_LOG_URL;
$image->link = $DOMAIN_NAME;
$image->description = "Feed provided by ". $SITE_TITLE. ". Click to visit.";
$rss->image = $image;
 
/**************************************************************
showSummery() - Fetch and build new feed
$url = Feed url
$num = Show the most recent posts (default = 10 )
$showfullfeed = true or false, for each article, show full text or summary (default false / summary text)
***************************************************************/
function showSummery($url,$num=10,$showfullfeed=false){
global $rss, $DOMAIN_NAME, $SITE_AUTHOR, $SITE_TITLE;
$num_items = $num;
@$rss1 = fetch_rss( $url );
if ( $rss1 )
{
        $items = array_slice($rss1->items, 0, $num_items);
        foreach ($items as $item)
        {
                $href = $item['link'];
                $title = $item['title'];
                if ( ! $showfullfeed ) {
                        $desc = $item['description'];
                }else{
                        $desc =  $item['content']['encoded'];
                }
                $desc .=  '<p>Copyright &copy; <a href="'.$DOMAIN_NAME.'">'.$SITE_TITLE.'</a>.  All Rights Reserved.</p>';
                $pdate = $item['pubdate'];
                $item = new FeedItem();
                $item->title = $title;
                $item->link = $href;
                $item->description = $desc;
                $item->date = $pdate;
                $item->source = $DOMAIN_NAME;
                $item->author = $SITE_AUTHOR;
                $rss->addItem($item);
        }
}
else
{
   echo "Error: Cannot fetch feed url - ".$url;
}
} // end showSummery()
//***************************************************************/
// Add your feed below:
// showSummery("http://path-to/url/feed",number-of-rss-items,false)
//****************************************************************/
showSummery("http://theos.in/feed/");
showSummery("https://www.cyberciti.biz/tips/feed/");
showSummery("https://www.cyberciti.biz/faq/feed/",5,false);
 
// get your news items from other feed and display back
$rss->saveFeed("RSS1.0", $TMP_ROOT."/rsscache/feed.xml");
?>

Customize script

Set temporary directory to cache rss feed, web server must be able to write to this directory.
$TMP_ROOT = "/tmp";
Set path to rss directory:
$RSS_DIR = "/home/lighttpd/theos.in/http";
Set your domain name, site title, description and author name:
$DOMAIN_NAME = "http://theos.in/";
$SITE_TITLE = "Your Site / blog Title";
$SITE_DESRIPTION = "Your Site / blog Description";
$SITE_AUTHOR = "Vivek";

Finally, set logo file name (replace logo.jpg with actual logo file name):
$SITE_LOG_URL = $DOMAIN_NAME."logo.jpg";

showSummery() function

showSummery($url,$num=10,$showfullfeed=false) fetch remote feed url and build new feed. It accept following arguments:

  • $url = Feed url
  • $num = Show the most recent posts (default = 10 )
  • $showfullfeed = true or false, for each article, show full text or summary (default false )

To combine two RSS feed http://theos.in/blog1/feed/ and http://theos.in/blog2/feed/, call showSummery():
showSummery("http://theos.in/blog1/feed/");
showSummery("http://theos.in/blog2/feed/");
showSummery("http://other-my-blog.com/feed/",5,true); // full feed

Test it

Open a web browser and type url http://your-domain.com/myfeed/rss.php

Download all files and required tools

=> You can download rss.php and required tools here (all GPL licensed except FeedCreator which is under LGPL)

Other tools – Yahoo Pipes

You can use 3rd party service such as Yahoo Pipes, which is an interactive feed aggregator and manipulator. Personally, I like to keep more control on my feed, hence I wrote this script.

How to: Get Feedburner RSS Subscriber Count in plain text or html code with feed count plugin

Recently, I saw few site displaying their feedburner feed count using html / text code. After googling I came across very nice plugin called Feed Count:

Feed Count 1.2 is the latest version of WordPress Plugin that displays the number of subscribers to your feedburner feed in text. You don’t have to use the feedburner chicklet, This plugin can be easily integrated into your wordpress them.

=> Download and Installation instructions

Howto add table to wordpress with WP-table plugin

Adding an html table to wordpress is problematic job in visual mode. My old solution was to go into text mode and enter html code. However there is a new plugin called WP-Table. It allows you to a table directly in the Visual mode or import from a spreadsheet. Cool isn’t it?

WP-table plugin to add table

According to author:

This plugin creates and manages tables for wordpress. So you can post i.e. sport results in a fixed table format. You don’t need to enter tables anymore in the plain text mode and the WYSIWYG editor didn’t damage the table layout. The table layout can be changed via a css file and you can import a csv file as table.

Download wp-table

Get FeedBurner MyBrand premium service free to use your own your domain

Thanks to mighty Google, now you can get FeedBurner Stats Pro and MyBrand version free of cost.

MyBrand is a premium FeedBurner service that allows publishers to showcase their feeds by serving them from their own domain. For example I can now use rss.theos.in instead of http://feeds.feedburner.com/ComputerTechnologyAndOsBlog

You need to setup a CNAME which is nothing but an alias or shortcut from one Internet name to another.

To get MyBrand:

a] Sign in to your FeedBurner account

b] Click My Account

c] Click MyBrand, enter your domains and activate

d] Just send email request to them

More information

MyBrand Overview and FAQ
MyBrand TechSupport FAQ

Thank you for making service free for all of us :)

Your WordPress blog may get hacked if you are using 2.1.1 version

I’ve updated my blog few days back. But in case if you are still running 2.1.1 makes sure you get updated version.

This morning we received a note to our security mailing address about unusual and highly exploitable code in WordPress. The issue was investigated, and it appeared that the 2.1.1 download had been modified from its original code. We took the website down immediately to investigate what happened.

It was determined that a cracker had gained user-level access to one of the servers that powers wordpress.org, and had used that access to modify the download file. We have locked down that server for further forensics, but at this time it appears that the 2.1.1 download was the only thing touched by the attack. They modified two files in WP to include code that would allow for remote PHP execution.

Read more