Sharing news and resources with clients through their WordPress dashboard

Creating a custom WordPress dashboard without a plugin.

I’ve been using a plugin to set up clients’ resources in the admin side of their own sites.

It looked impressive, but as I’m rebuilding my business to be more Simple (in keeping with the KISS principle) and Agile I’ve realised a code snippet will give me all that they need.

That is:

  • an iframe news widget in the client dashboard and
  • an admin menu link to a hidden resources page/site.

It’s one less plugin dependency and will let me update all clients in one go from my end. This is what I have come up with so far.

The screenshot

Dashboard.fw

The code

You can add the code below to your child theme’s functions php file.

In the video I am using WP Code Box. It’s a powerful plugin that come with a library of snippets, lets you save your own to the cloud and apply conditional logic. Although I’m keen to reduce plugins the amount of snippets I am using these days it getting to hard to manage in individual functions php files.

This is an affiliate link. The author  (Ovidiu) is a friend of this blog and we have the best discount code “beaverjunction” that offers 25% off the lifetime deal.  

The code here is amended from different sources. If you see a better way please let me know and I will update and credit you.

/**************************************************************************************************

Start of the section that adds a custom link to the WP admin menu and dashboard widget

***************************************************************************************************/

// Below adds the WP admin menu link

add_action( 'admin_menu', 'linked_url' );
function linked_url() {
add_menu_page( 'linked_url', 'Your Resources', 'read', 'my_slug', '', 'dashicons-welcome-learn-more', 3 );
}

add_action( 'admin_menu' , 'linkedurl_function' );
function linkedurl_function() {
global $menu;
$menu[3][2] = "https://yourwebsite.com/client-resources/"; 
}



/*********************************************************************************************

'Your  Resources' is where you can change the menu name.  

The two '3's set the menu position. This link explains the number positions.

The icon dashicons can be change to one here.

**********************************************************************************************/

// Below adds opening in a new browser tab (if required)

function my_target_blank() {
?>
<script type="text/javascript">
jQuery(document).ready( function($) {
$( "ul#adminmenu a[href$='https://yourwebsite.com/client-resources/']" ).attr( 'target', '_blank' );
});
</script>
<?php
}

// Below adds a dashboard widget

add_action( 'admin_head', 'my_target_blank' );
// addeds a dashboard widget

add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');

function my_custom_dashboard_widgets() {
global $wp_meta_boxes;

wp_add_dashboard_widget('custom_help_widget', 'WP Corner Shop News', 'custom_dashboard_help');
}

function custom_dashboard_help() {
echo '

<style>
p {text-align: center; font-size: 14px;}
</style>

<iframe src="https://yourwebsite.com/dashboard-notice/" scrolling="no" style="border:none;" height="240" width="460" title="News"></iframe>

<p><strong>Problems?</strong> Please email us on <a href="mailto:support@yourwebsite.com">support@yourwebsite.com</a>.</p>

<p>Here for <a href="https://yourwebsite.com/client-resources/" target="_blank"> training resources</a>.</p>
';
}
/*********************************************************************************************  

scrolling="no" need removing unless want to fix position an image as in the video.
End of the section that adds a custom link to the WP admin menu and dashboard widget

**********************************************************************************************/

Final Touches

  • I used Beaver Themer’s conditional logic with an URL variable (ie. https://yousite.com/dashboard-notice/?news=random-string) to hide content on the  resources and news pages.
  • Alternatively, if I did not want other to see, I could have put a random string on the URL and set the SEO plugin settings to no follow.
  • I’m considering having different resources and news links for the build period and converting to the regular ones when launched.
  • Also different links for different care packages.

Beaver Builder (my Page Builder of choice since 2014) are the sponsor for this blog. Thank you to them and you for reading.

     Tag:

Leave a Comment