Set primary domain anme at the registration form

Please advise how to preselect by default a specific domain name at the drop down field

  • Lindeni Mahlalela

    Hello digitalventures,

    I hope you are doing great today and thank you for your questions. I studied the code to see if we can do this with hooks and filters but it seems there are no usable filters on Multi Domains that can be used to achieve this.

    Fortunately, I have found the easiest way to achieve this without modifying any plugins.

    You should first create a new php file and paste the code:

    <?php
    add_action('wp_footer', 'md_pre_select_script' );
    function md_pre_select_script(){
    	$domain  =  esc_attr( $_GET['domain'] );
    	?>
    	<script type="text/javascript">
            jQuery(document).ready(function() {
    			jQuery("#domain option[value='<?php echo $domain; ?>']").attr('selected', 'selected');
            });
        </script>
    <?php }

    Then save and upload the file to your website in the folder 'wp-content/mu-plugins'. So you should have your new file in the folder like this:

    wp-content/mu-plugins/md-pre-select-domain.php

    Or you can paste the code in your theme's functions.php file, but remember to exclude the PHP opening tag:; '

    <?php

    Then, assume your network is hosted on yournetworkdomain.com and you have the multi domains (domain1.com, domain2.com and domain3.com) then you can set your external urls to redirect to:

    yournetworkdomain.com/wp-signup.php?domain=domain1.com

    Where yournetworkdomain.com is the primary domain of your multi site network and domain1.com is the domain you want to pre select based on the redirect. When redirecting from the external domain you will have to use the url format:

    yournetworkdomain.com/wp-signup.php?domain=the-preselected-domain.com

    Or if you are using our Pro Sites plugin, then the registration url will be like:
    yournetworkdomain.com/pro-site/?domain=the-preselected-domain.com

    All you have to do is replace the 'the-preselected-domain.com' with the domain you want pre-selected on the registration page, and that will be it.

    I hope that helps. Please let us know f you have any further questions.

    Have a nice day.
    Mahlamusa

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.