Alter Module Defaults

Introduction

If your theme is going to be powered by Live Composer you’ll probably want to adjust the styling of the LC modules to fit your overall theme design, which means changing the default values of the module options. That’s what we’ll be covering in this tutorial.

The Code

Straight to the point, here’s the code:

function alter_lc_defaults( $options, $id ) {

	// The array that will hold new defaults
	$new_defaults = array();

	// Alter defaults for Staff module
	if ( $id == 'DSLC_Staff' ) { 

		$new_defaults = array(
			'option_name' => 'new_value',
			'option_name' => 'new_value',
			'option_name' => 'new_value',
		);
	
	}

	// Call the function that alters the defaults and return
	return dslc_set_defaults( $new_defaults, $options );

} add_filter( 'dslc_module_options', 'alter_lc_defaults', 10, 2 );

Things to note:

  • Use a different function name ( not alter_lc_defaults ), to prevent possible conflicts.
  • Only the altered options defaults go in $new_defaults. The dslc_set_defaults function that’s called at the end will merge the altered and regular and return the full $options array.

Automated

Tracking which options you changed, finding out their IDs, filling up the $new_defaults array would be a time consuming task. So we created a little feature that does all that work for you.

To activate that feature go to  ds-live-composer.php and at the top you will see DS_LIVE_COMPOSER_DEV_MODE, set it to true. After you do that there will be a new “action” for modules (check the screenshot).

So, after you change up the module and want that current look to be the default look, click that button. A modal window will show up and the code you need is in the textarea, will look something like this:

if ( $id == 'DSLC_Blog' ) { 
	$new_defaults = array(
		'css_main_bg_color' => 'rgb(237, 236, 236)',
		'css_main_border_width' => '0',
		'css_title_font_weight' => '200',
		'css_excerpt_font_size' => '15',
		'css_excerpt_font_weight' => '400',
		'css_excerpt_line_height' => '27',
	);
}

Tutorial Finished

That concludes the tutorial on altering module defaults.

Still need help? Contact Us Contact Us