• Is there some way of having a hard coded link back to the main site from all network sites?

    In fact, I would prefer that every users site have one link back to the main site, hard coded into all sites.

    Is there some way of doing this without getting into editing php pages?

Viewing 15 replies - 1 through 15 (of 22 total)
  • If you want to hard code anything, you will need to edit php pages in your theme.
    I’m not exactly sure what you are wanting to do.

    Can you provide a link to your site please and a more detailed explanation?

    Thread Starter voopress

    (@voopress)

    I have a network setup so have a main site and then users blogs or sub-sites. On each of those sub-sites, I’d like to have a link back to the main site.

    I *don’t* want to get into editing things which will get overwritten with updates so am hoping to find a plugin or something.

    As for themes, yes, we hand edit each one to point back but we also need something at the top of each blog site.

    I hope that better explains.

    Thanks @voopress that does give me more info, unfortunately, I’m not sure.
    I moved your thread to the musltisite section. Hopefully someone with network experience will be able to help.

    Create a hostedon.php file to be added to your mu-plugins folder and add this:

    function mynetwork_hosted_on() {
    		if (is_multisite() && !is_admin()) {
    			$current_site = get_current_site();
    			if (!isset($current_site->site_name)) {
    				$site_name = ucfirst( $current_site->domain );
    			} else {
    				$site_name = $current_site->site_name;
    			}
    			$output = "<span class=\"footer-pipe\">|</span> ";
    			$output .= __('Hosted on') . ' <a href="https://'. $current_site->domain. $current_site->path. '">'. $site_name. '</a> ';
    			echo apply_filters('mynetwork_hosted_on', $output);
    		}
    	}
    add_action('wp_footer', 'mynetwork_hosted_on');

    Which will basically make the .php file you just added run everytime all the time (only in the front end) execute in every theme where the wp_footer(); code is placed (pretty much every theme), which is generally way at the very bottom. .. you can adjust to put inline CSS in there instead of a class

    This will also make it so you don’t have to edit all of those themes.

    Thread Starter voopress

    (@voopress)

    Wonderful, thank you so much for the input and help. I’ll give this a try.

    Just a note, if the $current_site code isn’t working for you, you could just hard code the main site link in there which would undoubtedly be faster ;/

    What I really wanted to point out was that if you added some code to the mu-plugins folder, it will execute for all sites on your multisite.

    Thread Starter voopress

    (@voopress)

    What I was really looking for was some way of hard coding the main site’s URL at the top of each blog site.

    But this is great to know. Just learning all of the fun things one can do with the network version.

    Thanks!

    Thread Starter voopress

    (@voopress)

    This might sound weird but I don’t have an mu-plugins directory?

    Thread Starter voopress

    (@voopress)

    Based on some reading I’ve done, looks like I simply hand create it so I think I’ve answered my own question on that last one ??

    However, the article states;

    >Popular plugins that do belong in this folder are ones like Domain >Mapping and New Blog Defaults. Please make sure to always read the >readme.txt included with any plugin, as it will specifically state if it >should be installed in this folder.

    Yet, I have these installed and working but they are in the standard plugin directory so, a bit confused.

    .. in the last few versions of WordPress there was code added to allow networked plugins from within the regular plugin directory; mu-plugins still exists for backwards compatibility for things like I suggested

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    That’s okay ?? Domain mapping actually works better in normal plugins these days.

    mu-plugins are great for single-file, no-interface, plugins. I use them for my sitewide changes that I want to be done on all sites.

    Thread Starter voopress

    (@voopress)

    Ah, got it. So, one really should ask when it comes to certain code then.
    Thanks, something more to add to my new knowledge.

    I tell you, I’m greatly impressed with WP considering that for many years, we’ve been working mainly with Joomla and only WP now and then.

    We seem to be turning the other way now, WP becoming more used than Joomla.

    Thread Starter voopress

    (@voopress)

    I figured out how to get this into a php file and run it but am getting the following error;

    mu-plugins]# php hostedon.php
    PHP Fatal error: Call to undefined function add_action() in /var/www/html/wp-content/plugins/mu-plugins/hostedon.php on line 16

    Maybe I am not understanding how this is supposed to run. I installed it into
    /wp-content/plugins/mu-plugins

    Thread Starter voopress

    (@voopress)

    Ok so I got it to run now but it doesn’t seem to be making any changes to the themes. I’m using mainly ‘elegant themes’

    first thing to do is check the footer of the themes to see if anything outputs, if not something is wrong with the code, or cache needs to be cleared ;/

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘Hard coded main site link in each site?’ is closed to new replies.