Contact Us

5-E / 22 BP , 2nd Floor
Near BK Chowk
Faridabad (Haryana), INDIA

Home Forums WordPress Add content in Short Code? Reply To: Add content in Short Code?


You have to use two functions. The first one is WordPress’ built-in shortcode_atts() function, which combines user shortcode attributes with native attributes and fills in the defaults where needed. The second function is the extract() PHP function, which does what its name suggests: it extracts the shortcode attributes.

function row_function($atts){
‘bg_color’ => ”,
), $atts));

You can take our shortcode one step further and add the ability to pass some content as an argument, which in this case will be a heading for the list of recent posts. To do this, we use a second parameter, $content, in the callback function and add it as an h3 heading before the list. The new function is as follows:

function row_function($atts, $content = null) {
‘bg_color’ => ”,
), $atts));
$return_string = ”;
$return_string .= ‘

$return_string .= $content;
$return_string .= ‘


return $return_string;

Now, we tell WordPress that this function is a shortcode:

function register_shortcodes(){
add_shortcode(‘row’, ‘row_function’);

In order to execute our register_shortcodes() function, we will tie it to WordPress’ initialization action:

add_action( ‘init’, ‘register_shortcodes’);


Tech9logy Creators


" The team @ Tech9logy have been outstanding in assisting our business with Salesforce development work. I can't speak highly enough of Tech9logy for their professional service and communication. They are extremely organized, can work independently, and are able to effectively multi-task to ensure that all projects are completed in a timely manner. "

Luke Hales
Director | Greens List Barristers

" I have been working with Tech9logy for over 2 years, developing a School Management App. They are a fantastic team and would recommend them to any person or company considering their services. "

John Ordovas
Trustee | Edugo

" We had a difficult and complicated project that required several custom modules. Team did a wonderful job! Their finished product exceeded our expectations and our users LOVE the added functionality! Would definitely recommend it. We have just opened a maintenance agreement for ongoing work with Tech9logy. Thanks again for all the hard work Team! "

Sean Hughes
CFO | Grindabit Interactive, Inc.

" We hired Tech9logy Creators to handle our online promotions and campaigns. Being professional in Digital Marketing strategy, great attention and suggestions was shared by tech9logy team for our site. I could tell that Tech9logy Team really understood our brand and brought the desired outcome for the project. Most importantly, we have seen growth to our business leads and steady increase in our traffic! Highly recommended for all online promotions. "

Aman Dalal
Deputy Manager - IT | Cosmo Films

contact us

trusted by the world's best