Getting And Defining Freelancer Layouts

Freelancer provides a helper function called freelancer_layout() that makes it super easy to either get or define a Freelancer Layout. Freelancer offers the following default layouts (listed in "Name" - "value" - "value function" format below, for your reference):

  • Right Sidebar - right_sidebar - freelancer_return_right_sidebar
  • Left Sidebar - left_sidebar - freelancer_return_left_sidebar
  • No Sidebar - no_sidebar - freelancer_return_no_sidebar
  • No Sidebar Narrow - no_sidebar_narrow - freelancer_return_no_sidebar_narrow

As mentioned above you can use the freelancer_layout() function to either get or define a Freelancer Layout. This means if you need to know what layout is assigned to a specific page you would do something like this:

$current_layout = freelancer_layout();

Or if you wanted to assign a specific layout to a page you'd do something like this:

add_filter( 'freelancer_layout', 'freelancer_return_right_sidebar' );

Note the use of the freelancer_layout filter hook as well as the freelancer_return_right_sidebar() function. Freelancer provides a simple helper function for each available layout as mentioned in the layout list above. So if you wanted to change the above filtered layout to a No Sidebar Narrow layout configuration then you'd simply change the callback function like so:

add_filter( 'freelancer_layout', 'freelancer_return_no_sidebar_narrow' );

So in a page template, for example, you could just paste one of the above example snippets into the template file and it should "force" that layout into any page using that template. But if you want to assign a custom layout to a page or post or conditionally controlled section of your site through a custom function you could do something like the following:

Below are examples of each Freelancer layout, defined through the freelancer_layout filter hook, using the appropriate Freelancer layout callback function: