Title: Shortcode only produces text &#8220;Array&#8221;
Last modified: June 27, 2017

---

# Shortcode only produces text “Array”

 *  Resolved [squasher](https://wordpress.org/support/users/squasher/)
 * (@squasher)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/shortcode-only-produces-array/)
 * Hi,
 * I’m creating a shortcode to apply styles to a site. The attributes determine (
   amongst other) the background colour so the user can influence this. However 
   the output only is “Array”. I think I’m doing something relatively simple wrong.
 * I’ve got the following code:
 *     ```
       function column_left_func( $atts, $content = null ) {
           $colour = shortcode_atts( array(
               'white' => '<div class="col left white">',
               'yellow' => '<div class="col left yellow">',
           ), $atts );
   
           return $colour . $content . '</div>';
       }
       add_shortcode( 'column_left', 'column_left_func' );
       ```
   
 * The shortcode I use is: [column_left colour=”white”]
 * On the website I only see “Array”. Not the content or divs from the code.
 * Somebody has a hint? I must be close?
 * Thanks!
    -  This topic was modified 8 years, 11 months ago by [squasher](https://wordpress.org/support/users/squasher/).

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/shortcode-only-produces-array/#post-9264806)
 * I think you’re using `shortcode_atts` incorrectly. `shortcode_atts` is for providing
   defaults for attributes that may or may not be set. Refer to the documentation
   to see why: [https://codex.wordpress.org/Function_Reference/shortcode_atts](https://codex.wordpress.org/Function_Reference/shortcode_atts)
 * It looks like you want to out put a different div based on an attribute on the
   shortcode. A way to do that would be:
 *     ```
       function column_left_func( $atts, $content = null ) {
       	switch ( $atts['colour'] ) {
       		case 'yellow':
       			$colour = '<div class="col left yellow">';
       			break;
       		case 'white':
       		default:
       			$colour = '<div class="col left white">';
       			break;
       	}
   
       	return $colour . $content . '</div>';
       }
       add_shortcode( 'column_left', 'column_left_func' );
       ```
   
 * Then you’d use either `[column_left colour="yellow"]` or `[column_left colour
   ="white"]`. Because of the `default:` case, `[column_left]` would output the 
   white version.
    -  This reply was modified 8 years, 11 months ago by [Jacob Peattie](https://wordpress.org/support/users/jakept/).
 *  Thread Starter [squasher](https://wordpress.org/support/users/squasher/)
 * (@squasher)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/shortcode-only-produces-array/#post-9264932)
 * Hi Jacob,
 * Thanks, you’re absolutely right! That was wat I’m trying to do and your solution
   works like a charm.
 * By the way, one (WordPress) thing is annoying: the shortcode is placed on a new
   line and in the frontend it outputs an empty <p>-tag. I can not get rid of it.
   Any ideas how to loose this <p>-tag?
 * Thanks again!
 *  Thread Starter [squasher](https://wordpress.org/support/users/squasher/)
 * (@squasher)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/shortcode-only-produces-array/#post-9264992)
 * I found this solution for the p-tags: remove_filter( ‘the_content’, ‘wpautop’);
 * It works, but is this wise to do? Not sure…
 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/shortcode-only-produces-array/#post-9265495)
 * No it’s probably not wise, you’ll mess with linebreaks throughout your site.
 * The thing to do would be to just use the shortcode inline, like so:
 *     ```
       [column_left colour="yellow"]Content goes here.
   
       New paragraph here.[/column_left]
       ```
   
 * That _should_ do it.
 *  Thread Starter [squasher](https://wordpress.org/support/users/squasher/)
 * (@squasher)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/shortcode-only-produces-array/#post-9265760)
 * I was afraid of that. However, I tried your suggestion as well, but everytime
   the page reloads the shortcode gets placed on the next line…
 * This is my code:
    `<div class="col-container">[column_left colour="yellow"]<h1
   class="blockquote">...`
 * And after a look at the preview the code is changed to:
 *     ```
       <div class="col-container">
   
       [kolom_links kleur="wit"]
       <h1 class="blockquote">
       ```
   
 * And back is the <p></p> above the H1!
 * Frustrating!
    -  This reply was modified 8 years, 11 months ago by [squasher](https://wordpress.org/support/users/squasher/).
 *  Thread Starter [squasher](https://wordpress.org/support/users/squasher/)
 * (@squasher)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/shortcode-only-produces-array/#post-9266128)
 * Well, solved it by adding some Javascript to remove empty p-tags…

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Shortcode only produces text “Array”’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 6 replies
 * 2 participants
 * Last reply from: [squasher](https://wordpress.org/support/users/squasher/)
 * Last activity: [8 years, 11 months ago](https://wordpress.org/support/topic/shortcode-only-produces-array/#post-9266128)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
