Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




add_shortcode [ WordPress Function ]

add_shortcode ( $tag, $func )
Parameters:
  • (string) $tag Shortcode tag to be searched in post content.
  • (callable) $func Hook to run when shortcode is found.
Uses:
  • $shortcode_tags
Defined at:



Add hook for shortcode tag.

There can only be one hook for each shortcode. Which means that if another plugin has a similar shortcode, it will override yours or yours will override theirs depending on which order the plugins are included and/or ran.

Simplest example of a shortcode tag using the API:

// [footag foo="bar"]
function footag_func($atts) {
    return "foo = {$atts[foo]}";
}
add_shortcode('footag', 'footag_func');

Example with nice attribute defaults:

// [bartag foo="bar"]
function bartag_func($atts) {
    extract(shortcode_atts(array(
        'foo' => 'no foo',
        'baz' => 'default baz',
    ), $atts));

    return "foo = {$foo}";
}
add_shortcode('bartag', 'bartag_func');

Example with enclosed content:

// [baztag]content[/baztag]
function baztag_func($atts, $content='') {
    return "content = $content";
}
add_shortcode('baztag', 'baztag_func');

Source


<?php
function add_shortcode($tag$func) {
    global 
$shortcode_tags;

    if ( 
is_callable($func) )
        
$shortcode_tags[$tag] = $func;
}
?>

Examples [ wp-snippets.com ]

Google Arama Sonuçlarý

Dahasý ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics