移除Wordpress自带Meta(功能)小工具中的无用链接

时间:2019-08-29   阅读:500

本文就百度知道中用户的提问作答:如何移除Wordpress自带Meta(功能)小工具中的无用链接。

移除Wordpress自带Meta(功能)小工具中的无用链接 文章 第1张 移除Wordpress自带Meta(功能)小工具中的无用链接 文章 第2张

使用插件Custom Meta Widget

 Custom Meta Widget 插件能让你有选择的移除Wordpress自带功能小工具中的链接,缺点是代码量太大。

使用代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
function coolwp_remove_meta_widget() {
    /*移除Wordpress自带的Meta小工具*/
    unregister_widget('WP_Widget_Meta');
    /*注册自己的Meta小工具*/
    register_widget('WP_Widget_Meta_Mod');
}
add_action( 'widgets_init', 'coolwp_remove_meta_widget' );
/*
自定义小工具扩展类
 */
class WP_Widget_Meta_Mod extends WP_Widget {
    function __construct() {
        $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Log in/out, admin, feed and WordPress links") );
        parent::__construct('meta', __('Meta'), $widget_ops);
    }
    function widget( $args, $instance ) {
        extract($args);
        $title = apply_filters('widget_title', emptyempty($instance['title']) ? __('Meta') : $instance['title'], $instance, $this->id_base);
        echo $before_widget;
        if ( $title )
            echo $before_title . $title . $after_title;
        ?>
        <ul><?php wp_register(); ?><li><?php wp_loginout(); ?></li><?php wp_meta(); ?></ul><?phpecho $after_widget;}function update( $new_instance, $old_instance ) {$instance = $old_instance;$instance['title'] = strip_tags($new_instance['title']);return $instance;}function form( $instance ) {$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );$title = strip_tags($instance['title']);?><p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p><?php}}

function coolwp_remove_meta_widget() { /*移除Wordpress自带的Meta小工具*/ unregister_widget('WP_Widget_Meta'); /*注册自己的Meta小工具*/ register_widget('WP_Widget_Meta_Mod'); } add_action( 'widgets_init', 'coolwp_remove_meta_widget' ); /* 自定义小工具扩展类 */ class WP_Widget_Meta_Mod extends WP_Widget { function __construct() { $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Log in/out, admin, feed and WordPress links") ); parent::__construct('meta', __('Meta'), $widget_ops); } function widget( $args, $instance ) { extract($args); $title = apply_filters('widget_title', emptyempty($instance['title']) ? __('Meta') : $instance['title'], $instance, $this->id_base); echo $before_widget; if ( $title ) echo $before_title . $title . $after_title; ?> <ul> <?php wp_register(); ?> <li><?php wp_loginout(); ?></li> <?php wp_meta(); ?> </ul> <?php echo $after_widget; } function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); return $instance; } function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); $title = strip_tags($instance['title']); ?> <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p> <?php } }

将上述代码粘贴到你在用的Wordpress主题下的functions.php中,更好的方式是写成一个Wordpress插件。

这种方式与使用Custom Meta Widget的方式相比:代码量更少,效率更高些。

上一篇:WordPress 小工具指定页面显示: Conditional Widgets

下一篇:WordPress 导出/导入小工具 Widget Importer & Exporter

网友评论