Removing Topic from title in bbpress forums

bbpress is a nice forum plugin that works with WordPress. 

In bbpress when you create a topic.. for example “How to create a bbpress topic?” , the title you get when viewing the topic is something like “Topic: How to create bbpress topic?”

.If you want to remove the “Topic” from bbpress forum topics, you can do it using “bbp_title” filter.

This is explained in the following code

 PHP |  copy code |? 
01
<?php
02
 
03
add_filter('bbp_title', 'custom_topic_title_bbp', 10, 2);
04
 
05
function custom_topic_title_bbp($title, $postarr) {
06
    $title = str_replace("Topic: ", "", $title);
07
    return $title;
08
}
09
 
10
?>

If you don’t know how to write code, just download the very tiny plugin below from here and activate it.

Custom-Topic-Title

Once you activate this plugin you’ll see your topic title as “How to create a topic?” instead “Topic: How to create a Topic?”

Posted in Pulgins | Leave a comment

Storing and retrieving optional values in wordpress

WordPress offers easier way to store optional values in the database. You can also retrieve those optional values and get back to them. You just need to know the name of the optional value that you want to retrieve.

Here is an example for that

For adding a new option or updating a new option you can use the following code

 PHP |  copy code |? 
1
<?php
2
    $custom_topic_title_options='Replace: ';
3
    update_option('custom_topic_title',$custom_topic_title_options);
4
?>

For retrieving option value from the database use the following code

 PHP |  copy code |? 
1
<?php
2
$replace=  get_option('custom_topic_title', '');
3
?>

Posted in Personal Notes | Leave a comment

Few functions I noticed about determining URL paths in wordpress plugin development

Here is a list of few functions available in WordPress to determine about URL paths in plugin development

  • plugin_dir_path($plugin_file) : The full plugin path. I can use _FILE_ php constant instead of $plugin_file too. For example , To use a JavaScript file located at JS foler we have to use like below 
     PHP |  copy code |? 
    1
    <?php
    2
    plugin_dir_path(_FILE_)."/js/myjavascript.js";
    3
    ?> 
  • plugins_url() : URL path to plugins directory
  • includes_url () : URL path to include directory
  • content_url() : URL path to content directory
  • admin_url() : URL path to admin directory
  • site_url() : URL path to WordPress installed directory
  • home_url() : The specified URL path to homepage
Posted in Personal Notes | Leave a comment

Common header information needed for wordpress plugin to work

These are the common information needed that needs to be placed above the wordpress plugin php file in the form of comments

  • Name : Name of the plugin
  • Description :  Description about the plugin
  • Plugin URI : The URL of the plugin from where we get the information and download it
  • Version : The version of the plugin
  • Author : The name of the plugin author
  • Author URI : URL of author’s website
  • License :  The license agreement of plugin

Here is a example header information for a plugin

 PHP |  copy code |? 
01
<?php
02
/* 
03
Name : My Plugin
04
Plugin URI : http://www.wordpresssources.com
05
Description: This is a plugin by Mahesh
06
Version : 1.0
07
Author : Mahesh
08
Author URI : http://wordpresssources.com
09
Licence : GPLv2
10
*/
11
?>

Posted in Personal Notes | Leave a comment

Things to keep in mind about file structure of a plugin directory

Suppose you want to write a plugin called “plugin_name” then the file structure must be as below

  • Directory “plugin_name” : Contains all the plugin files needed Inside this plugin we need the following fiile structure
    • File “plugin_name/plugin_name.php” : The main plugin file. This has code to execute the plugin
    • Folder “plugin_name/css” : For storing css stylesheets needed for the plugin
    • Folder “plugin_name/js” : For storing Javascript files needed for the plugin
    • Folder “plugin_name/images” : For storing images needed for the plugin
    • Folder “plugin_name/includes” : The additional include files needed for the plugin

This is one of simple approaches in writing a plugin

Posted in Personal Notes | Leave a comment

Myths about SEO in wordpress.com

We tend to use wordpress.com blogs time to time. It’s a great place to start our own blog and many of us have blogs on it too. One of the things that we disturbed is that why our pages are not displayed when we searched in search engines like google, yahoo and bing. We tend to ask for professional help which most of the times doesn’t do any good.

Here is a great article All About SEO on WordPress.com

I came across which nicely put forward how blogs on wordpress.com are optimized for SEO. We don’t need to be bothered about SEO for blogs on wordpress.com

It exposes the some of the myths as below

  1. I need a plugin for SEO.
  2. I need to regularly submit Sitemaps to Google so it knows I’m blogging regularly.
  3. The more tags and categories I use for a post, the better it is for Google.
  4. Creating several identical sites about sailboats and making frequent use of sailboat-related terminology in my posts will help me get a lot of sailboat-related traffic.
  5. One effective way to improve my blog’s SERP rank is to purchase or exchange links (sometimes known as “backlinks”) with as many bloggers as possible, so that there’s a lot of traffic going to my blog.
  6. SEO requires a strategy and possibly an expert.

Every blogger who is bothered about increasing page ranks should keep in mind these facts

Posted in Personal Notes | Tagged | Leave a comment

WordPress plugin for displaying code snippet

I was looking for a nice plugin for displaying code snippet in my wordpress blog. I found a great list of such plugins through this http://blog.templatemonster.com/2011/04/15/wordpress-plugins-code-snippets-displaying/

However out of the fifteen plugins listed out there, I liked only 3 of them

  1. Developer Formatter

  2. Google Syntax Highlighter

  3. Syntax Highlighter Evolved

The first one depends on the GeSHI highlight system and does the syntax highlighting at the server side. The later two does it on the client side by Alex Gorbatchev’s Syntax Highlighting code. 

All the three supports many number of programming languages

Alex Gorbatchev’s Syntax Highlighting code

I choose the first one because it’s on the server side. Although it may affect server performance with better caching plugins like Quick Cache you can always have a performance gain over others.

Hence my choice is to go for Developer Formatter

Posted in Personal Notes | Leave a comment

Applying a filter in a wordpress website

You can apply a filter in a wordpress website easily

Suppose you want your name to be added to the end of site title you can use a filter

  1. Use add_filter function to register the filter function
  2. Define the filter function which takes the input parameter as value to be filtered
  3. Return the filtered value of the function

 PHP |  copy code |? 
1
<?php
2
 
3
add_filter('wp_title', 'title_filter',10,2);
4
 
5
function title_filter($title,$postattr){
6
$title=$title." | Myname";
7
return $title;
8
}
9

Here in the add_filter function parameter 3 signifies the weight of the plugin and 2 defines the number of parameters it takes

You can add a function in the class too.. using the array attribute

 PHP |  copy code |? 
01
<?php
02
 
03
add_filter('wp_title',array('MyClass','title_filter'),10,2);
04
 
05
class MyClass{
06
  function title_filter($title,$postattr){
07
    $titile=$title." | ". "Myname";
08
    return $title;
09
    }
10
}

Posted in Personal Notes | Leave a comment

Adding a shortcode to your wordpress website

You can add a shortcode to your wordpress site very easily using a function

  1. Use the add_shortcode function to register the shortcode function
  2. Define the shortcode function
  3. Return a value in shortcode function to replace the shortcode value

 

 PHP |  copy code |? 
1
<?php
2
add_shortcode('Myshortcode', 'shortcode_function');
3
 
4
function shortcode_function($attr){
5
 
6
return "MyShortcode has been replaced by shortcode function";
7
}
8
 
9
?>

You can also use functions within a class as shortcode function too. For the just use the shortcode function name as array with first element in array signifying classname and second one defines the class function

 PHP |  copy code |? 
01
<?php
02
 
03
add_shortcode('MyshortcodeinClass', array('MyClass', 'shortcode_function');
04
 
05
class MyClass{
06
  function shortcode_function($attr){
07
    return "This is the value returned by the shortcode MyShortCodeinClass";
08
  }
09
}
10
?>

 

Posted in Personal Notes | Leave a comment

Few twitter accounts that post information about new themes

There are few twitter accounts that normally post information about new themes. This is mentioned here

As soon as I find others I just update them here

Posted in Themes | Leave a comment