• First off I am still wet behind ears with WP so if this has been answered somewhere else, or is contained in the API, then my search terminology is off.

    I am able to get the blog name for the parent/super blog, but how do I get the name for the sub-domain hosted site? I should qualify ‘name’.

    https://arresteddecay.com <= I can get “arresteddecay.com”
    https://trevor.arresteddecay.com <= I can not get the “trevor” part.

    The end purpose is to custom a stylesheet based on the actual sub-domain name. Not the user, not the title in the URL, but the sub-domain name. As this is dynamic, I will not have the sub-domain based site’s ID unless I can grab this automatically. I am sure I can create a theme function, but if WP has something in place, why not use it? ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The end purpose is to custom a stylesheet based on the actual sub-domain name.

    Use a custom css plugin activated on that sub blog? ??

    You can’t pull just the name part in one function. you CAN pull the full address, just like you would in single WP.

    But what you’re doing might not be the best way to do what you ultimately want. ??

    Thread Starter TrevorNet

    (@trevornet)

    This is the function that I dropped into the theme/functions.php file. It does what I need it to do. ??

    /**
     * @author Trevor Scott <[email protected]>
     * @version 1.0 2010-12-07
     *
     * Grab the subdomain portion of the URL. If there is no sub-domain, the root
     * domain is passed back. By default, this function *returns* the value as a
     * string. Calling the function with echo = true prints the response directly to
     * the screen.
     *
     * @param bool $echo
     */
    function arrested_subdomain($echo = false) {
    	$hostAddress = explode ( '.', $_SERVER ["HTTP_HOST"] );
    	if (is_array ( $hostAddress )) {
    		if (eregi ( "^www$", $hostAddress [0] )) {
    			$passBack = 1;
    		} else {
    			$passBack = 0;
    		}
    		if ($echo == false) {
    			return ($hostAddress [$passBack]);
    		} else {
    			echo ($hostAddress [$passBack]);
    		}
    	} else {
    		return (false);
    	}
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How do I get sub-domain name?’ is closed to new replies.