WordPress.org

Forums

Bootstrap Shortcodes for WordPress
[resolved] Inner row ? (11 posts)

  1. keving1
    Member
    Posted 1 year ago #

    Hello,

    I can't use inner row.

    Every time I put a [row] inside a column it breaks :-( So the nesting column is impossible...

    I had the same issue trying to create my own shortcode and I was hoping you found the solution :-p

    https://wordpress.org/plugins/bootstrap-3-shortcodes/

  2. Michael W.
    Member
    Plugin Author

    Posted 1 year ago #

    WordPress can't nest shortcodes of the same name (noted as a limitation in the Codex here). Unfortunately, because this is a limitation of WordPress and not of this plugin there isn't much we can do to fix it.

  3. keving1
    Member
    Posted 1 year ago #

    Hello,

    Thank you for your answer.

    Do you think it is possible to use other name for inner rows as [row_x] for exemple to avoid this ?

    They talk about this : http://www.pagelines.com/shop/plugins/grid-shortcodes/

    Nested Grid

    But I don't really know how to put that in a function :-)

  4. Michael W.
    Member
    Plugin Author

    Posted 1 year ago #

    We believe this would make this plugin overly complicated. We have to balance end-user ease with functionality and since WordPress itself doesn't support nested shortcodes of the same name we've decided not to support them in this plugin.

    Sorry!

  5. keving1
    Member
    Posted 1 year ago #

    I totally understand what you mean. I found the solution by adding some code to yours. It's not clean but it works for me. I'm not sure it will be for the en-user as you said.

    Thanks anyway :-)

  6. keving1
    Member
    Posted 1 year ago #

    And btw the plugin is excellent that's why I didn't want to use another one :-p

  7. Michael W.
    Member
    Plugin Author

    Posted 1 year ago #

    Thank you! We appreciate your support and the review!

  8. tasgray
    Member
    Posted 11 months ago #

    I've just encountered this while using your plugin (great plugin by the way). While I understand your reasons for not wanting to complicate things, in my case it renders the plugin almost useless. Is it not possible to add the ability to create [row-x][/row-x] for those of us who want to get tricky?

  9. Michael W.
    Member
    Plugin Author

    Posted 11 months ago #

    Thanks for your kind words!

    We haven't discussed nested grids in a while. I will bring it up with the other developers. I think it adds too much complication to the plugin and makes it difficult to document, but maybe we can work something out.

    I can't promise we will add this feature, and it can't say when, if ever, it'll make it's way to the WordPress.org repository, but we'll revisit the issue.

    Thanks again!

  10. keving1
    Member
    Posted 11 months ago #

    Hello,

    This is the solution that worked for me. As I say, it's not really clean but it can do the trick.

    add this to the bootstrap-shortcodes.php

    function row_inner($atts, $content = null)
    {
        return '<div class="row">' . do_shortcode($content) . '</div>';
    }
    add_shortcode('row_inner', 'row_inner');
    
    function bs_columninner( $atts, $content = null ) {
    
        extract( shortcode_atts( array(
          "lg"          => false,
          "md"          => false,
          "sm"          => false,
          "xs"          => false,
          "offset_lg"   => false,
          "offset_md"   => false,
          "offset_sm"   => false,
          "offset_xs"   => false,
          "pull_lg"     => false,
          "pull_md"     => false,
          "pull_sm"     => false,
          "pull_xs"     => false,
          "push_lg"     => false,
          "push_md"     => false,
          "push_sm"     => false,
          "push_xs"     => false,
          "xclass"      => false,
          "data"        => false
        ), $atts ) );
    
        $class  = '';
        $class .= ( $lg )             ? ' col-lg-' . $lg : '';
        $class .= ( $md )             ? ' col-md-' . $md : '';
        $class .= ( $sm )             ? ' col-sm-' . $sm : '';
        $class .= ( $xs )             ? ' col-xs-' . $xs : '';
        $class .= ( $offset_lg )      ? ' col-lg-offset-' . $offset_lg : '';
        $class .= ( $offset_md )      ? ' col-md-offset-' . $offset_md : '';
        $class .= ( $offset_sm )      ? ' col-sm-offset-' . $offset_sm : '';
        $class .= ( $offset_xs )      ? ' col-xs-offset-' . $offset_xs : '';
        $class .= ( $pull_lg )        ? ' col-lg-pull-' . $pull_lg : '';
        $class .= ( $pull_md )        ? ' col-md-pull-' . $pull_md : '';
        $class .= ( $pull_sm )        ? ' col-sm-pull-' . $pull_sm : '';
        $class .= ( $pull_xs )        ? ' col-xs-pull-' . $pull_xs : '';
        $class .= ( $push_lg )        ? ' col-lg-push-' . $push_lg : '';
        $class .= ( $push_md )        ? ' col-md-push-' . $push_md : '';
        $class .= ( $push_sm )        ? ' col-sm-push-' . $push_sm : '';
        $class .= ( $push_xs )        ? ' col-xs-push-' . $push_xs : '';
        $class .= ( $xclass )   ? ' ' . $xclass : '';
    
        $data_props = $this->parse_data_attributes( $data );
    
        return sprintf(
          '<div class="%s"%s>%s</div>',
          esc_attr( $class ),
          ( $data_props ) ? ' ' . $data_props : '',
          do_shortcode( $content )
        );
      }

    Don't forget to add 'columninner' to the add_shortcode function at line 65.

    function add_shortcodes() {
    
        $shortcodes = array(
          'alert',
          'badge',
          'breadcrumb',
          'breadcrumb-item',
          'button',
          'button-group',
          'button-toolbar',
          'caret',
          'carousel',
          'carousel-item',
          'code',
          'collapse',
          'collapsibles',
          'column',
          'columninner',
    
    ...

    Then you just have to call [row_inner] and [columninner] everytime you want inner rows and cols :-)

  11. Michael W.
    Member
    Plugin Author

    Posted 10 months ago #

    Thanks for posting this!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags