Friday, June 1, 2012

Add new BBcode in WordPress



You may  need to add new BBcode after you install WordPress.  This will speed your posting a lot.
Below is how I add newBBCode in my Wordpress:
http://jiansenlu.comze.com/wordpress

Go to directory: wordpress/wp-content/themes/fresh-ink-magazine
(I used the theme fresh-ink-magazine, you need to go to your customized theme directory)
in functions.php
1) Add following code for youtube BBcode:

function yt_func($atts, $VIDEO_ID="") {
$ytcode='<iframe class="youtube-player" type="text/html" width="100%" height="390" src="http://www.youtube.com/embed/'.$VIDEO_ID.'" frameborder="0"></iframe>';
     return $ytcode;
}
add_shortcode('yt', 'yt_func');

the BBcode usage is [yt]Video_Id[/yt],
example:
[yt]JW5meKfy3fY[/yt]

The BBcode will not be shown in the editor menu. But you can use it in the post body.

2) The following is to create an Adsense BBcode:

function showads()
{$ad_code = 'put your your ad sense code here';
return $ad_code;
}

add_shortcode('ads','showads');

Replace   'put your your ad sense code here';   to your Adsense code.
The BBcode usage: [ads]

More on how to add the BBcode in the editor menu can be found:
http://wp.tutsplus.com/tutorials/theme-development/wordpress-shortcodes-the-right-way/

No comments:

Post a Comment