114 posts
  • Has referred 1+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+3 more
mountainthemes says

Really, shortcodes are bad, shortcodes are evil. You (as a developer) have not control of the generated markup and 90% of the time a complete mess of code is generated by Wordpress. I will no insert ANY shortcode in my theme from now and you should do the same. (thanks god Envato has a strict idea on that).

1875 posts YOU TOUCH IT YOU BUY IT
  • Has referred 200+ members
  • Has sold $500,000+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+6 more
FRESHFACE says

Just yesterday I was thinking about creating a similar WP + Shortcodes + TinyMCE thread to start some more general debate instead of just people posting possible solutions, etc.

Does anyone have an idea why WordPress never fixed this? Anyone did some extensive research on this topic? Is it even considered an issue?

1186 posts
  • Has been part of the Envato Community for over 4 years
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 more
Smartik says

You (as a developer) have not control of the generated markup and 90% of the time a complete mess of code is generated by Wordpress.

Can you expand this, how do you see this control of the generated markup?

448 posts Don't be a HATER!
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+5 more
webinpixels says

Is this about auto p wrapped by WordPress on shortcode output? In my other accounts, currently I follow how woocommerce generate the shortcode output, instead writing the output inside the shortcode function, I use locate_template() and php include() function. With locate_template(), user can override the output in a child theme, more info. And so far, the output is clean from WordPress auto p (at least for me), not sure why – but it works! Just example, incase it useful for some authors :D

function wip_shortcode_locate_template( $template_name ){
    $template_path = 'shortcode-output/'; //the dir name, user can override in child theme, e.g. 'child-theme/shortcode-output/carousel.php'

    $template = locate_template( trailingslashit( $template_path ) . $template_name );
    return $template;
}

/**
 * $template_name = file name (with extensions)
 * $args = array of arguments that should passed into the file
 */
function wip_shortcode_get_template( $template_name, $args = array() ){
    if ( $args && is_array($args) )
        extract( $args );

    $located = wip_shortcode_locate_template( $template_name );

    include( $located );
}
Now, in the shortcode function. simply go like this

function my_carousel_shortcode( $atts, $content = null ) {
    extract(shortcode_atts(array(
        'image_ids' => '',
        'width'    => '600',
        'height'    => '367',
    ), $atts));

    ob_start();

    $args = array(
        'image_ids' => $image_ids,
        'width'    => $width,
        'height' => $height,
        'content' => $content
        );

    wip_shortcode_get_template( 'carousel.php', $args );

    $carousel = ob_get_clean();

    return $carousel;
}
in the carousel.php, we can simply call the attributes and run the output
<?php
/** carousel.php - generate carousel shortcode*/
?>

<!-- define the html output here -->
<?php
//you can simply call the attributes that passed into the file
$ids = $image_ids;
$wrap_width = $width;
$wrap_height = $height;
$more_content = $content;

....... etc.
?>

Personally I hate shortcode too, that’s why in my latest theme (under my personal account) – I only use one shortcode, to call custom content inside the content manager. No problem till now, buyers never ask about other shortcodes :D

by
by
by
by
by
by