WordPress short code usage

Source: Internet
Author: User
Tags bbcode closing tag php file response code

WordPress has added a short code API starting with version 2.5. Similar to BBCode on BBS, the short code can also easily add features for articles or pages, in addition, the response code is more flexible and powerful than the BBCode. The following MK introduces the response code.

I. INTRODUCTION to postal code

Coding code allows developers to create macro content in the form of functions to generate content. This concept may seem a bit vague, but it is actually a very simple and practical function, as long as you write basic PHP functions, you can use the response code. The following describes how to use the response code using the actual example.

II. Response code

The response code supports both closed and self-closed tags, and supports using parameters in the tag. The specific form of response code depends on how developers compile the response code.

The code is as follows: Copy code

[Mydomaincode] Some Content [/mydomaincode] // Close the tag
[Mydomaincode] // self-closing tag
[Mydomaincode title = "example"] // the tag with a parameter
[Mydomaincode] <p> <a href = "#"> <span> content </span> </a> </p> [/mydomaincode] // you can enter text or HTML
[Mydomaincode] Content [mydomaincodesecond] more content [/mydomaincodesecond] // nested


III. Example of postal code

Before using the response code, you must first define the response code in the functions. php file of the topic. For example:

The code is as follows: Copy code
Function my‑code_function ($ atts, $ content = null ){
// $ Atts represents the parameters of the response code, and $ content is the content in the tag.
Extract (export code_atts (array (// use the extract function to parse parameters in the tag
"Title" => 'title' // assign a default value to the parameter. You can call $ directly to add the parameter name output parameter value.
), $ Atts ));
// Return content
Return '<div class = "mycoding code">
<H3> '. $ title.' <P>
'. $ Content .'
</P>
</Div> ';
}

 
Add_shortcode ("msc", "my‑code_function ");

// Register the response code and use the [msc] label to call the response code.
Add the above code to functions. php, and a simple deployment code is created. We can call the deployment code through the [msc] [/msc] tag, for example:

 

The code is as follows: Copy code

[Msc title = "welcome"] this is Mingkai's blog. Welcome to this blog [/msc]

Enter the above call in the article or page content. You can output a welcome statement at the corresponding position and define the corresponding CSS in style.css to assign a style to the short code.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.