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.