17713433920 info@mac163.com
自定义您的WordPress仪表板欢迎消息
自定义您的WordPress仪表板欢迎消息

自WordPress 3.3以来,似乎很多人都不想展示称为“欢迎面板”的新功能。我想那些不想显示此消息的人会尝试向客户隐藏此框,这就是为什么我认为与其隐藏它,还应该自定义它并使用自己的内容来显示它。为了显示自定义欢迎消息,我们将创建一个小插件。这样,即使升级到新版本的WordPress,显示的消息也将是您的消息,而不是默认消息。

让我们开始吧!

让我们创建一个插件

要创建插件,请在wp-content / plugins下创建一个新文件夹,并将其命名为custom-dashboard-message。在此文件夹中创建一个名为custom-dashboard-message.php的文件,并在代码编辑器中将其打开(通过Coda 2很棒!)。只需将此代码粘贴到新创建的文件中:

<?php
/*
Plugin Name: Custom Dahsboard Message
Plugin URL: https://www.wpexplorer.com/
Description: A little plugin to modify default dashboard welcome message
Version: 0.1
Author: WExplorer
Author URI: https://www.wpexplorer.com/
*/

这段代码只是创建了一个插件…是的,我知道,WordPress对您来说太简单了!

否,我们不需要创建一个函数来删除默认的仪表板消息,以便可以在添加自己的自定义欢迎面板内容之后使用。通过在welcome_panel挂钩上使用remove_action,我们删除了默认的挂钩wp_welcome_panel函数,该函数返回了welcome面板的内容。

/**
 * Remove the default welcome dashboard message
 *
 * @access      public
 * @since       1.0 
 * @return      void
*/
remove_action( 'welcome_panel', 'wp_welcome_panel' );

我们的自定义欢迎消息

如果现在转到仪表板(请不要忘记激活插件!),您将不再看到任何欢迎屏幕–是的!因此,现在我们可以创建自己的自定义函数,并将其钩到welcome_panel钩中,以便显示它。这部分很简单,您需要做的就是创建一个自定义函数并为欢迎面板添加所需的内容。在我的示例中,我从默认内容wp_welcome_panel()默认函数开始。仅因为它允许我使用已格式化的内容,所以它更容易。因此,我只是复制并粘贴了此功能(在wp-admin / includes / dashboard.php下找到它),然后对其进行了编辑。

这是我的函数的样子(请注意,函数如何通过add_action跟随并连接到welcome_panel中)。

/**
 * Custom welcome panel function
 *
 * @access      public
 * @since       1.0 
 * @return      void
 */
function wpex_wp_welcome_panel() { ?>

	<div class="custom-welcome-panel-content">
		<h3><?php _e( 'Welcome to your custom dashboard Message!' ); ?></h3>
		<p class="about-description"><?php _e( 'Here you can place your custom text, give your customers instructions, place an ad or your contact information.' ); ?></p>
		<div class="welcome-panel-column-container">
			<div class="welcome-panel-column">
				<h4><?php _e( "Let's Get Started" ); ?></h4>
				<a class="button button-primary button-hero load-customize hide-if-no-customize" href="http://your-website.com"><?php _e( 'Call me maybe !' ); ?></a>
					<p class="hide-if-no-customize"><?php printf( __( 'or, <a href="%s">edit your site settings</a>' ), admin_url( 'options-general.php' ) ); ?></p>
			</div><!-- .welcome-panel-column -->
			<div class="welcome-panel-column">
				<h4><?php _e( 'Next Steps' ); ?></h4>
				<ul>
				<?php if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_for_posts' ) ) : ?>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-edit-page">' . __( 'Edit your front page' ) . '</a>', get_edit_post_link( get_option( 'page_on_front' ) ) ); ?></li>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add additional pages' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li>
				<?php elseif ( 'page' == get_option( 'show_on_front' ) ) : ?>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-edit-page">' . __( 'Edit your front page' ) . '</a>', get_edit_post_link( get_option( 'page_on_front' ) ) ); ?></li>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add additional pages' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Add a blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
				<?php else : ?>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Write your first blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add an About page' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li>
				<?php endif; ?>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-view-site">' . __( 'View your site' ) . '</a>', home_url( '/' ) ); ?></li>
				</ul>
			</div><!-- .welcome-panel-column -->
			<div class="welcome-panel-column welcome-panel-last">
				<h4><?php _e( 'More Actions' ); ?></h4>
				<ul>
					<li><?php printf( '<div class="welcome-icon welcome-widgets-menus">' . __( 'Manage <a href="%1$s">widgets</a> or <a href="%2$s">menus</a>' ) . '</div>', admin_url( 'widgets.php' ), admin_url( 'nav-menus.php' ) ); ?></li>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-comments">' . __( 'Turn comments on or off' ) . '</a>', admin_url( 'options-discussion.php' ) ); ?></li>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-learn-more">' . __( 'Learn more about getting started' ) . '</a>', __( 'http://codex.wordpress.org/First_Steps_With_WordPress' ) ); ?></li>
				</ul>
			</div><!-- .welcome-panel-column welcome-panel-last -->
		</div><!-- .welcome-panel-column-container -->
	<div><!-- .custom-welcome-panel-content -->

<?php }
add_action( 'welcome_panel', 'wpex_wp_welcome_panel' );

您只需编辑代码的这一部分即可创建您的内容,添加链接,图像,表单或其他任何内容。

最终插件代码

这是完整的插件代码,请享用!

<?php
/*
Plugin Name: Custom Dahsboard Message
Plugin URL: https://www.wpexplorer.com/
Description: A little plugin to modify default dashboard welcome message
Version: 0.1
Author: WExplorer
Author URI: https://www.wpexplorer.com/
*/

/**
 * Remove the default welcome dashboard message
 *
 */
remove_action( 'welcome_panel', 'wp_welcome_panel' );

/**
 * Custom welcome panel function
 *
 * @access      public
 * @since       1.0 
 * @return      void
 */
function wpex_wp_welcome_panel() { ?>

	<div class="custom-welcome-panel-content">
		<h3><?php _e( 'Welcome to your custom dashboard Message!' ); ?></h3>
		<p class="about-description"><?php _e( 'Here you can place your custom text, give your customers instructions, place an ad or your contact information.' ); ?></p>
		<div class="welcome-panel-column-container">
			<div class="welcome-panel-column">
				<h4><?php _e( "Let's Get Started" ); ?></h4>
				<a class="button button-primary button-hero load-customize hide-if-no-customize" href="http://your-website.com"><?php _e( 'Call me maybe !' ); ?></a>
					<p class="hide-if-no-customize"><?php printf( __( 'or, <a href="%s">edit your site settings</a>' ), admin_url( 'options-general.php' ) ); ?></p>
			</div><!-- .welcome-panel-column -->
			<div class="welcome-panel-column">
				<h4><?php _e( 'Next Steps' ); ?></h4>
				<ul>
				<?php if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_for_posts' ) ) : ?>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-edit-page">' . __( 'Edit your front page' ) . '</a>', get_edit_post_link( get_option( 'page_on_front' ) ) ); ?></li>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add additional pages' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li>
				<?php elseif ( 'page' == get_option( 'show_on_front' ) ) : ?>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-edit-page">' . __( 'Edit your front page' ) . '</a>', get_edit_post_link( get_option( 'page_on_front' ) ) ); ?></li>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add additional pages' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Add a blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
				<?php else : ?>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Write your first blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add an About page' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li>
				<?php endif; ?>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-view-site">' . __( 'View your site' ) . '</a>', home_url( '/' ) ); ?></li>
				</ul>
			</div><!-- .welcome-panel-column -->
			<div class="welcome-panel-column welcome-panel-last">
				<h4><?php _e( 'More Actions' ); ?></h4>
				<ul>
					<li><?php printf( '<div class="welcome-icon welcome-widgets-menus">' . __( 'Manage <a href="%1$s">widgets</a> or <a href="%2$s">menus</a>' ) . '</div>', admin_url( 'widgets.php' ), admin_url( 'nav-menus.php' ) ); ?></li>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-comments">' . __( 'Turn comments on or off' ) . '</a>', admin_url( 'options-discussion.php' ) ); ?></li>
					<li><?php printf( '<a href="%s" class="welcome-icon welcome-learn-more">' . __( 'Learn more about getting started' ) . '</a>', __( 'http://codex.wordpress.org/First_Steps_With_WordPress' ) ); ?></li>
				</ul>
			</div><!-- .welcome-panel-column welcome-panel-last -->
		</div><!-- .welcome-panel-column-container -->
	<div><!-- .custom-welcome-panel-content -->

<?php }
add_action( 'welcome_panel', 'wpex_wp_welcome_panel' );

微信二维码

微信扫描二维码联系我们!
我们在微信上24小时期待你的声音
提供外贸路由器设备产品,轻松翻墙,解答:WP主题推荐,WP网站建设,Google SEO,百度SEO,专业服务器环境搭建等!


需要提供WordPress主题/插件的汉化服务可以随时联系我们!另外成品WordPress网站以及半成品WordPress网站建设,海外Google SEO优化托管服务,百度SEO优化托管服务,Centos/Debian服务器WP专用环境搭建,WP缓存服务器搭建,我们都是你的首选,拥有多年WP开源程序服务经验,我们一直在坚持客户体验,没有最好,只有更好!
回到顶部