I would like to change this line of code. right now when

I would like to change this line of code. right now when I go to my dashboard I stay on the same page. I have to change this line of code

Site Admin
to this

admin panel</p></div>

I would like to open a new tab when the user goes from the site to the admin panel?

  • Ivan Shulev

    Hey Orlando ,

    I hope you are having a nice day so far!

    To make your dashboard link open in a new tab/window, please add the following code in your functions.php / custom code plugin:

    function wpmu_5433_custom_target() { ?>
    	<script type="text/javascript">
    		document.addEventListener( 'DOMContentLoaded', function () {
    			var dashboardLinkParent = document.getElementById('wp-admin-bar-dashboard');
    			var dashboardLink = dashboardLinkParent.firstChild;
    			dashboardLink.target = '_blank';
    		}, false );
    	</script>
    <?php }
    add_action('wp_footer', 'wpmu_5433_custom_target');

    This will add a target _blank attribute to the link for the dashboard. Keep in mind that whether it will open in a new tab or window depends on the browser. You do not have influence on that.

    I would like to change this line of code. right now when I go to my dashboard I stay on the same page. I have to change this line of code

    Site Admin
    to this

    admin panel</p></div>

    I am not certain if that is related to the issue with dashboard link opening in new tab. Please provide more details if it is another issue.

    I hope this helps and I wish you an awesome day ahead!

    Ivan

  • Orlando

    do I have to follow this https://premium.wpmudev.org/manuals/creating-your-own-plugin-for-custom-code-additions/

    and if not what must I do?

    Do I have to make a plugin or do I add this code the code below
    function wpmu_5433_custom_target() { ?>
    <script type="text/javascript">
    document.addEventListener( 'DOMContentLoaded', function () {
    var dashboardLinkParent = document.getElementById('wp-admin-bar-dashboard');
    var dashboardLink = dashboardLinkParent.firstChild;
    dashboardLink.target = '_blank';
    }, false );
    </script>
    <?php }
    add_action('wp_footer', 'wpmu_5433_custom_target');

    directly in my functions.php below or exactly where?

  • Luís

    Hi Orlando ,

    Hope you're doing well today!

    You can add the code given by my teammate Ivan Shulev directly in your functions.php.

    Or, you can create a plugin, following the instructions given in the article you mentioned above and using this code:

    <?php
    
    /*
    Plugin Name: My Custom plugin
    Plugin URI: http://mysite.example.com
    Description: A plugin for my custom code. Changes the from address on WordPress outgoing email
    Author: Your Name
    Version: 1.0
    Author URI: http://mysite.example.com
    */
    
    function wpmu_5433_custom_target() { ?>
    	<script type="text/javascript">
    		document.addEventListener( 'DOMContentLoaded', function () {
    			var dashboardLinkParent = document.getElementById('wp-admin-bar-dashboard');
    			var dashboardLink = dashboardLinkParent.firstChild;
    			dashboardLink.target = '_blank';
    		}, false );
    	</script>
    <?php }
    add_action('wp_footer', 'wpmu_5433_custom_target');
    
    ?>

    You will need to create a folder to your plugin (i.e my-plugin) inside wp-content/plugins and upload the .php file to inside of it.

    I already created an example (see attached) of the plugin in a .zip file, so you can upload it in the Plugins section, as a normal plugin.

    I hope this information has been helpful. If I can help you in this or other questions, please let me know!

    Cheers, Luís

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.