Title: Get shortcode attributes in format using php
Last modified: August 20, 2016

---

# Get shortcode attributes in format using php

 *  [jrod691](https://wordpress.org/support/users/jrod691/)
 * (@jrod691)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/get-shortcode-attributes-in-format-using-php/)
 * I am looking for a way to use a shortcode attribute in the php display format
   so I can reuse a format script for several templates.
 * I have several duplicated custom field templates with keys that have incremental
   indexes on the end such as:
 * Template #0:
    [content-box-0]
 * Template #1:
    [content-box-1]
 * Template #2:
    [content-box-2]
 * etc…
 * Say I have the following shortcode:
 * `[cft template=1 format=1]`
 * I also have entered a [cft] shortcode format using PHP in the Custom Field Template
   settings page.
 * In that format PHP I want to be able to access shortcode attributes like so:
 * `
    <?php $all_custom_fields = base_get_all_custom_fields(); // returns an array
   of all custom fields on the page; $cft_template = ?; //some way to get shortcode
   template attribute which would be 1 in the above shortcode
 *  echo '<div>' . $all_custom_fields['content-box-' . $cft_template] . '</div>';
   ?
   >
 * Anyone know how I can do this? I’ve been struggling with it for a week now.
 * [http://wordpress.org/extend/plugins/custom-field-template/](http://wordpress.org/extend/plugins/custom-field-template/)

The topic ‘Get shortcode attributes in format using php’ is closed to new replies.

 * ![](https://ps.w.org/custom-field-template/assets/icon-256x256.png?rev=1966286)
 * [Custom Field Template](https://wordpress.org/plugins/custom-field-template/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/custom-field-template/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/custom-field-template/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-field-template/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-field-template/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-field-template/reviews/)

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 0 replies
 * 1 participant
 * Last reply from: [jrod691](https://wordpress.org/support/users/jrod691/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/get-shortcode-attributes-in-format-using-php/)
 * Status: not resolved