BBCode in Wordpress - W/O a plugin

Status
Not open for further replies.

Apathetic

Active Member
899
2011
241
0
  • Edit your theme's functions.php and add after <?php:
    Code:
    include 'shortcode.php';
  • Create a new file in your theme's directory named shortcode.php
  • Paste this:
    Code:
    <?php
    function underline( $attr, $content = null ) {
        return '<font style="text-decoration:underline;">' . $content . '</font>';
    }
    add_shortcode('u', 'underline');
    ?>

    u is the shortcode tag
    underline is the function name
    <font style="text-decoration:underline;"> is what comes before the content of the shortcode
    </font> comes after the shortcode

  • To use the shortcode, wrap them with content here [/u ]
    [*]To add more, just duplicate the function above and replace the values to suit your needs.

    Here's a function for the tag with the post's title used as an alt tag
    [INDENT][CODE]function image( $attr, $content = null ) {
    return '<img src="' . $content . '" alt="'.get_the_title($ID).'"/>';
    }
    add_shortcode('img', 'image');[/CODE][/INDENT]
    [/LIST]

    Read More:
    [LIST]
    [*][URL="http://codex.wordpress.org/Shortcode_API"]Shortcode API - WordPress Codex[/URL]
    [/LIST][/COLOR]
 
11 comments
how to modiying tag <code>
i have wp site just still use <blockquote > but this tag make padding space big i has been modifiying but still like that

and the tag code not work perfect like i try at stlecss to modifiying with put back color still nothing happen

help please
 
how to modiying tag <code>
i have wp site just still use <blockquote > but this tag make padding space big i has been modifiying but still like that

and the tag code not work perfect like i try at stlecss to modifiying with put back color still nothing happen

help please


You can modify blackquote class in your style.css.

If your theme has already got a tag named 'code'. Define a new class like

link
{
blah:blah;
boom:boom;

}

and use <link>content</link>
 
how to modiying tag <code>
i have wp site just still use <blockquote > but this tag make padding space big i has been modifiying but still like that

and the tag code not work perfect like i try at stlecss to modifiying with put back color still nothing happen

help please

edit your theme's style.css

Code:
blockquote {padding: 5px !important}
 
c75982d80a.jpg


how to get dis wid <code>link</code>?????
 
^
Code:
function code( $attr, $content = null ) {
    return '<code>' . $content . '</code>';
}
add_shortcode('code', 'code');

edit: you mean the design? Edit your css file (y)
 
Code:
code {
    background-color: #F7F7F7;
    border: 1px dashed black;
    color: black;
    display: block;
    font-family: verdana;
    font-size: 7pt;
    padding: 7px;


}

Put the above in your style.css, its a basic one, modify according to your wish.
 
how to make links clickable?
If bbcode is:
Code:
[ur l] link here [/url]

note: there is an space between the first url, other the link would be live
 
Last edited:
Code:
function linkcode( $attr, $content = null ) {
    return '<a href"' . $content . '" rel="nofollow">'.$content.'</a>';
}
add_shortcode('url', 'linkcode');
 
Last edited:
Status
Not open for further replies.
Back
Top