Switch nav menu alignment programmatically

In GP Premium you have the option to use the navigation as a header so you can have the below layout:

Nav menu left aligned
Nav menu left aligned

The option can be found by going to Appearance -> Customize -> Layout -> Header and choose the Use Navigation as Header option. You can then head to Appearance -> Customize -> Layout -> Primary Navigation and select Navigation Alignment options of left, center and right. But what if we wanted different settings for the various pages? For example, what if we wanted the menu to be left-aligned throughout the site apart from the homepage?

No problem! GeneratePress has Customizer settings that are filterable. This means that we can apply filters to change the Customizer settings conditionally. Put the following code to your functions.php or through the use of a functionality plugin.

add_filter( 'option_generate_settings','tu_move_navigation' );
function tu_move_navigation( $options )
{
	if ( is_front_page() ) {
		$options['nav_alignment_setting'] = 'right';
       }

	return $options;
}

The above code will right align the navigation bar on the homepage only.

Nav menu right-aligned
Nav menu right-aligned