Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • There are good reasons why shortcode nesting doesn’t work. But it does make the job harder when nesting. I managed with a little help from Google to use the below code, which will allow you to nest one column set.

    This is how nested shortcodes are suggested to work. Notice the row-b and column-b

    [row]
    [column sm="6"]
    
    start of col 1
    
    [row-b]
    [column-b sm="6"]
    
    sub col 1
    
    [/column-b]
    [column-b sm="6"]
    
    sub col 2
    
    [/column-b]
    [/row-b]
    
    end of col 1
    
    [/column]
    [column sm="6"]
    
    col 2
    
    [/column]
    [/row]

    Functions to add to your functions.php. Essentially it extracts the shortcode and re-wraps it.

    add_shortcode('column-b', 'col_cb');
    add_shortcode('row-b', 'row_cb');
    
    function col_cb( $atts, $content ) {
    	$attr = array();
    	foreach($atts as $key=>$att){
    		$attr[] = ' ' . $key . '="' . $att . '"';
    	}
    	$content = do_shortcode('[column' . implode('', $attr) . ']' . $content . '[/column]');
    	return $content;
    }
    
    function row_cb( $atts, $content ) {
    	$attr = array();
    	foreach($atts as $key=>$att){
    		$attr[] = $key . '="' . $att . '"';
    	}
    	$content = do_shortcode('[row' . implode('', $attr) . ']' . $content . '[/row]');
    	return $content;
    }

    You could nest deeper by just adding.

    add_shortcode('column-c', 'col_cb');
    add_shortcode('row-c', 'row_cb');
    add_shortcode('column-d', 'col_cb');
    add_shortcode('row-d', 'row_cb');

    Orginal post (This helped me)
    https://wordpress.stackexchange.com/questions/125328/how-to-parse-nested-shortcodes

    Once again thanks to the plugin maker, this is a great plugin I use in all my sites.

    Thanks got it working, but I changed it a little bit to use the wp-content folder.

    file: classes/class-spider.php
    line: 446 (approx)

    change

    file_put_contents('.head.htm',$head_HTML);

    to

    $upload_dir = wp_upload_dir();
    $this->upload_dir = $upload_dir['basedir'] . '/easy-site-importer/';
    if(!file_exists($this->upload_dir)){
    	mkdir($this->upload_dir, 0777);
    }
    file_put_contents($this->upload_dir . 'head.htm',$head_HTML);

    And then (about line 497)

    $this->meta[$page]=array_merge(array('Title' => $title[1], 'Scrape' => $scrape, 'Filter' => $actual_HTML, 'Formatted' => $this->proc_HTML, 'Images' => $this->images_copy),get_meta_tags('.head.htm'));

    to

    $this->meta[$page]=array_merge(array('Title' => $title[1], 'Scrape' => $scrape, 'Filter' => $actual_HTML, 'Formatted' => $this->proc_HTML, 'Images' => $this->images_copy),get_meta_tags($this->upload_dir . 'head.htm'));

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