Permanantly Name All 'Home Pages' on Mutli-site..

Hi.
I am seeking help with a piece of PHP code I could place in a themes.php function file?
I wish to permanently fix all 'Home Pages' (on a multi-site install) to have the same 'Page-Title' (that cannot be changed)!

In short:- to have 'all site' 'home pages' titled :- 'Back Of Card'.

Regards
Johnv

  • Adam Czajczyk

    Hello John,

    I hope you're well today and thank you for your question!

    Assuming that all the sites on your Multisite are using the very same theme, you can add the code to the "functions.php" file of that theme. However, it might be more "reliable" to use it as an mu-plugin ("Must Use" plugin) as it would make it "theme-independent", so even if one of the sub-sites would be using a different theme, code should be applied.

    The code that should do the trick would be:

    function wpmu_fixed_wp_title( $title ) {
    if ( is_front_page() ) {
    	return 'Back Of Card';
        }
    }
    add_filter( 'pre_get_document_title', 'wpmu_fixed_wp_title', 99, 1 );

    To adjust the title, simply replace Back Of Card with some other string in this line:

    return 'Back Of Card';

    To use it in "functions.php" file, copy the code "as is" and past it into that file. To use it as an mu-plugin instead:

    - create an empty file with php extension (e.g. "fixed-multisite-title.php")
    - open file for editing with "clean text" editor (such as e.g. Notepad++, Sublime or similar)
    - put php opening tag in the very first line:

    <?php

    - below that tag copy the entire code from above
    - save the file
    - access the Multisite via FTP or cPanel "File Manager" tool
    - upload the file to the "/wp-content/mu-plugins" folder; if there's no "mu-plugins" folder inside "wp-content", just create empty one and then upload the file into it.

    I hope that helps :slight_smile:

    Best regards,
    Adam

  • Predrag Dubajic

    Hi John,

    I had a look at your site and it looks like your themes are not using the default WP development rules and some things are different than what you would see in Default WP themes.
    For example, instead of using wp_head function to get the blog info you are using wp_title to call only the title.
    That causes hook used in Adam's code not to work as there's no such hook on your site.
    Using the below modified code should do the trick for your specific themes:

    function wpmu_fixed_wp_title( $title ) {
    if ( is_home() || is_front_page() ) {
    	return 'Back Of Card';
        }
    }
    add_filter( 'wp_title', 'wpmu_fixed_wp_title', 99, 1 );

    Best regards,
    Predrag

  • Predrag Dubajic

    Hi John,

    Where did you add the code, in your theme or as mu-plugin?
    I mean, either way it should do it automatically but there's a difference with mu-plugin requiring <?php tag at the start, as Adam mentioned above.

    Could you give me access to your file via FTP or cPanel so I can check the code on your end because it works fine on my installation?
    You can send us your details using our contact form https://premium.wpmudev.org/contact/#i-have-a-different-question and the template below:

    Subject: "Attn: Predrag Dubajic"
    - Site login url
    - WordPress admin username
    - WordPress admin password
    - FTP credentials (host/username/password)
    - cPanel credentials (host/username/password)
    - Link back to this thread for reference
    - Any other relevant urls/info

    Best regards,
    Predrag

  • john

    Hi Predrag.

    Thanks for your return reply.

    I have granted access to web-me.at via WPMU Dev Dashboard.

    I am changing server soon, so best not to use up your time if it can be solved via WP Dashboard!

    The Theme I have placed the code in is "Free Sites" ( not 'free sites').

    This Theme is currently serving the three sub-sites:-

    web-me.at/123me
    web-me.at/catch22
    web-me.at/1for1

    I hope this meets with your approval?
    Thanking you in advance.

    Regards
    johnv

  • Predrag Dubajic

    Hi John,

    I just checked the sites you've mentioned and it seems to me that the code is working properly, all three of them are using "Back Of Card" as title, which is the text from code that needs to be changed to one you want to use.
    Here's how those subsites behave on my end:
    https://monosnap.com/file/MzXahb6bT3Qz7t8bmfqLtfSUVmhAHQ

    Isn't that what you were aiming for or are we missing something here? :slight_smile:

    Best regards,
    Predrag

  • john

    Hi Predrag.

    I am not getting that result for some reason!!!

    web-me.at123me: was set read to "back of card info", which should then read "back of card" if the code is working! I have now set it to read "Test Info".

    web-me.at/catch22: is reading "Sample Page".

    web-me.at/1for1: is reading "Forwarding Page".

    I could not open your download 'screen shot' as I use Linux, but notice that the 'tab title' in the 'browser bar' does read "Back of Card"!

    Is that what you are seeing!

    Perhaps we have been at cross purposes (I not having paid notice of the the Tab Bar!).

    Have you chaps been meaning "Title Bar" and I meaning actual 'top of page' page "Page Titles"????

    Ooooops!!!!!

    Regards

    Johnv

  • Adam Czajczyk

    Hi John!

    Oops, it seems I misunderstood your request initially. Somehow, I assume you mean the title as in "the title that you see on a browser tab". So, the code does work but it's addressing a different issue :slight_smile: I'm sorry, that was my mistake.

    That being said, in this case we'd need to use a slightly different code so instead of the one you already added, try this one please:

    function wpmu_fixed_wp_title( $title, $id = null ) {
    	if ( is_front_page() && $id == get_option( 'page_on_front' ) ) {
    		$title = 'Back Of Card';
        }
    	return $title;
    
    }
    add_filter( 'the_title', 'wpmu_fixed_wp_title', 10, 2 );

    Let me know if that did the trick for you, please.

    Best regards,
    Adam

  • Adam Czajczyk

    Hi Johnv!

    I've checked the code on site and fixed that. There where two issues:

    1) I assumed you'll be replacing the original code and not adding new one in addition to the previous one so I used the same function name. That's something that is always causing an error as there cannot be two functions of the same name.

    Therefore, in the new code I changed "wpmu_fixed_wp_title" function name to "wpmu_fixed_page_title" function name so now you can keep both codes active on site at the same time, if you wish.

    2) While putting the code there, a closing } bracket must have been accidentally removed from " my_disable_quick_edit" function above; I added it (see line #570).

    It seems to be working fine and the page titles are now being changed to "Back Of Card".

    I hope that helps :slight_smile:

    Best regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.