分类: 建站知识

  • 一个好的wordpress外贸网站应该具备以下5个特点

    简洁

    客户是来看产品信息的,网站越简洁,产品越突出,客户最容易看到。

    实用

    外贸网站是做给客户的,功能一定不要太多,突出自己的产品即可。

    准确

    外贸网站是给外国人看的,信息必须要准确,要把网站上的每一句话,都要以对方能看得懂的语言准确无误的表达出来。有些人,为了图省钱,直接用翻译软件把自己的产品和公司信息,翻译一下就放在网站上了。这样的信息,放上去,还不如不放。你不放,客户还不知道,你有多不专业。

    速度快

    客户是没有耐心,等着看你的网站的。那么多的网站,又不是非看你的不可。所以,网站的打开速度一定要快。不能在服务器上省钱,这是最得不偿失的。简站WP主题

    即时反馈

    有些人在外贸网站上放了邮件和社交软件等联系方式,但是,客户和他联系了,回复的很慢,等看到了才回复,可能已经过去好多天了。世界那么大,同行那么多,客户不可能,只联系你一家,不要因为反馈不即时,而错失了客户。

  • wordpress禁用Rest API

    将以下代码插入到functions.php文件中即可

    add_filter("json_enabled", "__return_false");
    add_filter("json_jsonp_enabled", "__return_false");
    add_filter("rest_enabled", "__return_false");
    add_filter("rest_jsonp_enabled", "__return_false");
    remove_action("init", "rest_api_init");
    remove_action("rest_api_init", "rest_api_default_filters", 10);
    remove_action("parse_request", "rest_api_loaded");
    remove_action("wp_head", "rest_output_link_wp_head", 10);
    remove_action("template_redirect", "rest_output_link_header", 11);
    remove_action("auth_cookie_malformed", "rest_cookie_collect_status");
    remove_action("auth_cookie_expired", "rest_cookie_collect_status");
    remove_action("auth_cookie_bad_username", "rest_cookie_collect_status");
    remove_action("auth_cookie_bad_hash", "rest_cookie_collect_status");
    remove_action("auth_cookie_valid", "rest_cookie_collect_status");
     
    add_filter("rest_authentication_errors", function () {
        return new WP_Error("rest_disabled", __("The REST API on this site has been disabled."), ["status" => rest_authorization_required_code()]);
    });
  • wordpress禁用Feed

    将以下代码插入到functions.php文件中,即可禁用Feed。

    function wpjzp_feed_disabled()
    {
        wp_die("Feed已经关闭, 请访问网站<a href="" . get_bloginfo("url") . "">首页</a>!");
    }
     
    add_action("do_feed", "wpjzp_feed_disabled", 1);
    add_action("do_feed_rdf", "wpjzp_feed_disabled", 1);
    add_action("do_feed_rss", "wpjzp_feed_disabled", 1);
    add_action("do_feed_rss2", "wpjzp_feed_disabled", 1);
    add_action("do_feed_atom", "wpjzp_feed_disabled", 1);
  • wordpress禁用xmlrpc

    将以下代码插入到functions.php文件中即可

    add_filter("xmlrpc_enabled", "__return_false");
    add_filter("xmlrpc_methods", function ($methods) {
        unset($methods["pingback.ping"]);
        return $methods;
    });
  • wordpress移除wp_head不常用代码

    把不常用的代码移除,让wordpress快起来,想要非一样的感觉,可以试试。

    remove_action("wp_head", "wp_generator");
    foreach (["rss2_head", "commentsrss2_head", "rss_head", "rdf_header", "atom_head", "comments_atom_head", "opml_head", "app_head"] as $action) {
        remove_action($action, "the_generator");  //删除 head 中的 WP 版本号
    }
    remove_action("wp_head", "rsd_link");                        //删除 head 中的 RSD LINK
    remove_action("wp_head", "wlwmanifest_link");                //删除 head 中的 Windows Live Writer 的适配器?
     
    remove_action("wp_head", "feed_links_extra", 3);            //删除 head 中的 Feed 相关的link
     
    remove_action("wp_head", "index_rel_link");                //删除 head 中首页,上级,开始,相连的日志链接
    remove_action("wp_head", "parent_post_rel_link", 10);
    remove_action("wp_head", "start_post_rel_link", 10);
    remove_action("wp_head", "adjacent_posts_rel_link_wp_head", 10);
     
    remove_action("wp_head", "wp_shortlink_wp_head", 10, 0);    //删除 head 中的 shortlink
    remove_action("wp_head", "rest_output_link_wp_head", 10);    // 删除头部输出 WP RSET API 地址
     
    remove_action("template_redirect", "wp_shortlink_header", 11);        //禁止短链接 Header 标签。
    remove_action("template_redirect", "rest_output_link_header", 11);    // 禁止输出 Header Link 标签。
  • wordpress禁止多地同时登录

    wordpress禁止用户在不同地点同时登录,管理员除外。

    function pcl_user_has_concurrent_sessions()
    {
        return (is_user_logged_in() && count(wp_get_all_sessions()) > 2);
    }
     
    add_action("init", function () {
        // 除了管理员,其他人不允许多地同时登陆。
        if (!current_user_can("manage_options")) {
            if (!pcl_user_has_concurrent_sessions()) {
                return;
            }
            $newest = max(wp_list_pluck(wp_get_all_sessions(), "login"));
            $session = pcl_get_current_session();
            if ($session["login"] === $newest) {
                wp_destroy_other_sessions();
            } else {
                wp_destroy_current_session();
            }
        }
    });
  • 实现wordpress一篇文章只允许同一IP评论一次

    在使用wordpress建站时,常常遇到被垃圾留言困扰,有些通过机器发垃圾留言,一发就是成百上千条,这个很烦人,因此,有些人干脆直接在wordpress网站上把留言评论功能给关闭了。

    如果你的wordpress主题必须要使用留言评论,有一个办法可以规避这个问题,即实现wordpress一篇文章只鸡同一IP的人评论一次就可以。

    将以下代码添加到functions.php中

    // 一篇文章只允许同一IP评论一次
    //获取评论用户的ip,参考wp-includes/comment.php
    function wdp_getIP() {
      $ip = $_SERVER['REMOTE_ADDR'];
      $ip = preg_replace( '/[^0-9a-fA-F:., ]/', '', $ip );
        
      return $ip;
    }
    function wdp_only_one_comment( $commentdata ) {
      global $wpdb;
      $currentUser = wp_get_current_user();
      
      // 不限制管理员发表评论
      if(empty($currentUser->roles) || !in_array('administrator', $currentUser->roles)) {
        $bool = $wpdb->get_var("SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = ".$commentdata['comment_post_ID']."  AND (comment_author = '".$commentdata['comment_author']."' OR comment_author_email = '".$commentdata['comment_author_email']."' OR comment_author_IP = '".wdp_getIP()."') LIMIT 0, 1;");
        if($bool)
          wp_die('留言已提交,请勿重复留言。<a href="'.get_permalink($commentdata['comment_post_ID']).'">点此返回</a>');
      }
    
      return $commentdata;
    }
    add_action( 'preprocess_comment' , 'wdp_only_one_comment', 20);
  • 自字义wordpress摘要显示的字数长度

    以下代码可以实现,自定义wordpress文章摘要显示的字数长度,数值为字符号,汉字占两个字符。

     
    function new_excerpt_length($length) {
    return 100;
    }
    add_filter('excerpt_length', 'new_excerpt_length');
    
    
  • 禁用WordPress中的搜索功能

    以下代码可以禁止使用wordpress中的搜索功能

     
    function wdp_filter_query( $query, $error = true ) {
     
    if ( is_search() ) {
    $query->is_search = false;
    $query->query_vars[s] = false;
    $query->query[s] = false;
     
    // to error
    if ( $error == true )
    $query->is_404 = true;
    }
    }
     
    add_action( 'parse_query', 'wdp_filter_query' );
    add_filter( 'get_search_form', create_function( '$a', "return null;" ) );
    
    
  • 给wordpress用户个人资料添加自定义字段

    在制作个人博客时,有时会需要显示作者的QQ或微信,下面这段代码就可以实现这个功能。

     
    function wdp_new_contactmethods( $contactmethods ) {
    // Add QQ
    $contactmethods['qq'] = 'qq';
    //add WeiXin
    $contactmethods['weixin'] = 'weixin';
     
    return $contactmethods;
    }
    add_filter('user_contactmethods','wdp_new_contactmethods',10,1);
    
    

    在需要调用的位置通过以下代码调用即可

     
    <?php echo $curauth->qq; ?>