114 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Exclusive Author
  • Has been a member for 2-3 years
  • Italy
  • Bought between 1 and 9 items
  • Referred between 1 and 9 users
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).

1864 posts YOU TOUCH IT YOU BUY IT
  • Bought between 100 and 499 items
  • Referred between 200 and 499 users
  • Has been a member for 4-5 years
  • Won a Competition
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
+1 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?

1074 posts
  • Forum Superstar
  • Most Wanted Bounty Winner
  • Envato Studio (Microlancer) Beta Tester
  • Author had a Free File of the Month
  • Bought between 50 and 99 items
  • Referred between 50 and 99 users
  • Europe
  • Has been a member for 3-4 years
  • Exclusive Author
+1 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?

438 posts Don't be a HATER!
  • Exclusive Author
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Bought between 10 and 49 items
  • Referred between 10 and 49 users
  • Won a Competition
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Has been a member for 4-5 years
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