Hard coded main site link in each site? (23 posts)

  1. voopress
    Posted 3 years ago #

    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?

  2. 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?

  3. voopress
    Posted 3 years ago #

    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.

  4. 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.

  5. Frumph
    Posted 3 years ago #

    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="http://'. $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.

  6. voopress
    Posted 3 years ago #

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

  7. Frumph
    Posted 3 years ago #

    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.

  8. voopress
    Posted 3 years ago #

    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.


  9. voopress
    Posted 3 years ago #

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

  10. voopress
    Posted 3 years ago #

    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.

  11. Frumph
    Posted 3 years ago #

    .. 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

  12. 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.

  13. voopress
    Posted 3 years ago #

    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.

  14. voopress
    Posted 3 years ago #

    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

  15. voopress
    Posted 3 years ago #

    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'

  16. Frumph
    Posted 3 years ago #

    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 ;/

  17. voopress
    Posted 3 years ago #

    If you mean check the footers to see if they changed, no, they all have their original footers. I no longer see any errors when running the code but of course, no change either.

    I don't have any caching going on yet since the site is only under development. The browser cache was cleared.

    I don't mind trying again but wonder maybe we should simply hand code them just to be safe.

  18. Jesús Franco
    Posted 3 years ago #

    Have you checked the source code output? Maybe there is a trick with those "elegant themes" (some friends use it with a lot of troubles), not showing your span added to the footer because it doesn't have a style for becoming visible.

    Thinking on this, your could make your link appear on the top of the page, even with fancy styling like overlaying, with a bit of CSS absolute positioning.

  19. voopress
    Posted 3 years ago #

    For now, I just hard coded all of the themes but once the site is up, I'll keep this environment for dev so can better test then.

    Also, I'll have to get my designer on this thread because she is more into css and other things such as that.

    What we'd love to have is a tiny logo on the top and a small banner at the bottom of each subdomain and subdirectory site.

    Which actually brings me to the next post I'll be making or have, asking if both can co-exist on the same network install.

  20. Jesús Franco
    Posted 3 years ago #

    Good luck with that, since once you get updates, every change you do will be lost, and is not really wise stay away from updates. I'd recommend you and your designer explore into child themes, in order to keep your changes while updating your themes.

    Logo and small banner, almost everything is posible if you try the right tricks. I'd recommend you the tutorials on http://tympanus.net/codrops/ and http://css-tricks.com/

    About the network with both modes, subdomain and subdirectory. It's just too much complicated, if not impossible.

  21. voopress
    Posted 3 years ago #

    I'm not saying I give up, I'm saying in the interest of continuing to work on the site, I have hard coded for now.
    I'll get back on the code in a few days to a week and see if I can get that working. Looking at each theme, I noticed that many are different even though they are all Elegant themes.

    As for domain/directory, I found a post from some others looking for the same thing and added to that thread for some input.
    I did a little testing and it seemed to work but it might not be worth the trouble as you mention.

    Worse comes to worse, I have to run another server, no big deal.


  22. Jesús Franco
    Posted 3 years ago #

    If you use Elegant themes, you could try adding code to the end of your body, as (I think) all their themes provides a box where you can put code like i.e. google analytics, without touching your themes at all. These changes won't be overriden with each upgrade to your theme files. This is usually used for JS code, however you can include any code you like.

    About the mix of domain/directory, where did you post about that? I'd like to know how people are giving a try to that. Just for curiosity ;-)

  23. voopress
    Posted 3 years ago #

    I would certainly prefer this over a plugin. However, the plugin also does some very interesting things that I love.

    I found WpMuBar, a plugin which lists all of the blogs on the site by simply checking them in the config, has a nice logo area which users can click on to get to the main site, and even some social icons to boot.

    If I could find a way of doing this ourselves, that would be very cool considering the author isn't responding to anything so far. It is the holidays of course.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.