Swap home page based on user role, Elementor layout breaking


I work for a manufacturer that has normal boring consumers and wholesale dealers. We want to display a different home page for these two different audiences. Consumers will get more of a brand overview, while dealers will see current promotions available only to them.

Dealers will have to log in to see this, and I have already created a role for them called “Wholesale.” I have also created two home pages: one for consumers (which is set in WordPress to be the front page) and the one for dealers. The dealer page is a copy and paste of the consumer page, which was built with Elementor.

I have come up with a function (in the theme’s function.php file) that does exactly what I want, except for one flaw: the layout of the dealer home page content is broken.

Here’s the code:

// Display different home page for dealer vs consumer
function change_home_dealer($content) {
  if (is_user_logged_in()) {
    $current_user = wp_get_current_user();
    $user = new WP_User($current_user -> ID);
    if (in_array('Wholesale', $user->roles)){
      if (is_front_page()){
        // Grab ID of the page I want to be the dealer front page
        $dealer_front_id = 2885;
        $dealer_content = get_post($dealer_front_id);
        $content = $dealer_content->post_content;
        return $content;
      } else {
        return $content;
  } else {
    return $content;
add_filter('the_content', 'change_home_dealer');
, , MCDAndrew 8 months 0 Answers 94 views 0

Leave an answer