Home>Support>Programmatically Define Prebuilt Page Layouts

Programmatically Define Prebuilt Page Layouts

Notice: This thread is over two years old; the information may be outdated. Please consider creating a new thread if you require free support. If you have an active SiteOrigin Premium license, you can email our premium support desk at [email protected].

Hi there,

First of all – great plugin – good work to all developers involved.

Second, is there a way to programmatically define Page Layouts? Reading your (somewhat limited) documentation on it just shows to create a new “Page” with the desired layout, and then you can clone it on other Posts/Pages etc.

But if I don’t want a “page” existing just for this template, is there a way I can create a Prebuilt Layout in the Functions.php or elsewhere?

Thanks,
Jamie.

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 11 years, 2 months ago Greg Priday
    Hi, I Work Here

    Hi Jamie

    Glad to hear you’re liking our little plugin :)

    OK, so let me take a quick stab at explaining how to create a prebuilt layout. Vantage is one theme that’s adding it’s own prebuilt layouts. This is the code it’s using.

    function vantage_prebuilt_page_layouts($layouts){
    	$layouts['default-home'] = array ( ... );
    
    	return $layouts;
    }
    add_filter('siteorigin_panels_prebuilt_layouts', 'vantage_prebuilt_page_layouts');

    So basically it’s filtering the layouts var passed through the siteorigin_panels_prebuilt_layouts filter.

    You’ll need to activate development mode in Page Builder to get the array you need to pass to the layouts array. In your WordPress config file (wp-config.php) add the following.

    define('SITEORIGIN_PANELS_DEV', true);

    In your development environment, create a page using Page Builder. Save that page, then inspect the HTML source code of the page and search for the string “// Page Builder Data dump”. You should see a full PHP array that fully defines the layout. This is what you pass to the $layouts array.

    Just be sure to add a key called ‘name’ with the name of the prebuilt layout.

    To get a better idea, download our Vantage theme and check out the file inc/panels.php

    Hope that helps :)

  2. 10 years, 8 months ago Diego Vagnoli

    Hello Jamie,
    I can’t see the Data Dump in source code.
    I added define(‘SITEORIGIN_PANELS_DEV’, true); in wp-config.php but I can’t find any dump in source, not in backend or in frontend of the page.

    I tryed using the serialized data as described here: https://wordpress.org/support/topic/how-to-add-prebuilt-layouts-to-a-custom-theme
    but I have a lot of HTML in that database field, so including it in a php function as a variable it’s quite a job.

    If I wont be able to see the dump, maybe I can process that panels_data postmeta with a custom script so I can transform that into an array to use in vantage_prebuilt_page_layouts function?

  3. 10 years, 8 months ago Diego Vagnoli

    SOLVED

    I’ve searched in plugin script for “// Page Builder Data dump” and I found it in inc/debug.php
    don’t know why it’s not working, anyway I put this piece of code from debug.php

    <?php
    echo "ID, ‘panels_data’, true));
    echo “\n\n–>”;
    ?>

    in my page template, and now I can see the array well formatted. Cool :)

  4. 10 years, 8 months ago Diego Vagnoli

    ops, I didn’t include the code in the code tag, sorry it got deleted. here it is:

    echo "<!--\n\n";
    	echo "// Page Builder Data dump\n\n";
    	var_export( get_post_meta($post->ID, 'panels_data', true));
    echo "\n\n-->";
    
  5. 10 years, 8 months ago Diego Vagnoli

    sorry if I keep posting, but I’m not done yet :(

    I used that array and the prebuilt layout is present, but if I load it it’s just empty.

    this is the code I’ve used:

    1) I’ve included the unserialized array in a variable, like this.

    $prebuilt_unserialized = [pasted here the array that was printed by code I pasted in previous post]
    

    2) then I’ve copied the method used in siteorigin-panels.php line 979

    function mycustom_prebuilt_page_layouts($layouts){
    	$layouts[''my-custom-1] = wp_parse_args(
    			array(
    				'name' => __('My Prebuilt Layout', 'siteorigin-panels'),
    			),
    			$prebuilt_unserialized
    		);
    
    	return $layouts;
    }
    add_filter('siteorigin_panels_prebuilt_layouts', 'mycustom_prebuilt_page_layouts');
    

    Any idea why?

  6. 10 years, 8 months ago Diego Vagnoli

    sorry I made an error in editing the pasted code above

     $layouts[''my-custom-1]  

    is actually

     $layouts['my-custom-1']
Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More