pc wx

扫码关注“沃之涛科技”安全登录

扫码登录 微信内打开可长按扫码一键登录

登录即表示同意服务协议条款

我已确认并阅读 服务协议条款

如果您丢失了所有信息,可联系管理员QQ:1500351892。

添加域名
确定删除该域名吗?
该操作无法复原
用户头像

用户

ID: 剩余积分:

无赠送
100积分
100
赠100积分
500积分
500
赠400积分
1000积分
1000
赠1300积分
2000积分
2000
赠7000积分
5000积分
5000
注意事项

积分仅限于AI文章写作也可以用于Wordpress下的SEO合集插件“快速排名”“智能改写”功能使用;

充值仅用于消费,不可变更,退款,提现,请慎重选择!

支付宝
微信
购买积分: 100
赠送积分: 0
应付金额: ¥100

用户邮箱

验证码

点此继续访问
确定删除吗?
该操作无法复原
分类编辑
序号
分类名称
操作
{{item.index}}

暂无数据

{{item.index}}.
暂无数据
行业资讯

wordpress添加代码功能的实现

浏览次数:1121 发布日期:2022-06-15 18:14:46
  1. 要实现添加代码首先要认识wordpress添加事件的钩子函数add_action($event,$func)。字面意思添加一个操作,一个行动。

  2. $event参数是钩子事件,一般是执行的时机。例如:after_setup_theme主题启动执行,publish_post发布文章执行。$func自定义的函数或者类的方法。

  3. 今天我们讲解wp_head加载前端页面头部时执行(或者说往头部添加内容,或者去除内容),wp_footer底部添加内容。

  4. add_action( 'wp_head', [$this,'baiduseo_mainpage'],1 );
 public function baiduseo_mainpage(){
        $baiduseo_zz = get_option('baiduseo_zz');
        if(isset($baiduseo_zz['toutiao_key']) && $baiduseo_zz['toutiao_key'] ){
            echo '<script>
    	          /*seo合集头条推送*/
                (function(){
                var el = document.createElement("script");
                el.src = "https://sf1-scmcdn-tos.pstatp.com/goofy/ttzz/push.js?'.esc_attr($baiduseo_zz['toutiao_key']).'";
                el.id = "ttzz";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(el, s);
                })(window)
                </script>';
        }
        if(is_home() || is_front_page()){
            $seo = get_option('seo_init');
            if($seo){
                if(isset($seo['keywords']) && $seo['keywords']){
                    echo '<meta name="keywords" content="'.esc_attr($seo['keywords']).'">'."\n\r";
                }
                if(isset($seo['description']) && $seo['description']){
                    echo '<meta name="description" content="'.esc_attr($seo['description']).'">'."\n\r";
                }
            }
        }elseif(is_category()){
            $cate = get_the_category();
            
            if(isset($cate[0]->cat_ID)){
                $seo = get_option('baiduseo_cate_'.$cate[0]->cat_ID);
                
                if(!empty($seo)){
                    if(isset($seo['keywords']) && $seo['keywords']){
                        
                        echo sprintf('<meta name="keywords" content="%s" />'."\n",esc_attr($seo['keywords']));
                    }
                    if(isset($seo['description']) && $seo['description']){
                        echo sprintf('<meta name="description" content="%s" />'."\n",esc_attr($seo['description']));
                    }
                }
            }
        }elseif(is_single()){
            add_action( 'the_content', [$this,'BaiduSEO_addlink']);
        }
    }

上面的代码是在头部head标签中添加头条推送的js,设置页面的keywords、description,以及加载头部时,更改文章内页的内容。wp_footer钩子的用法与wp_head相似,不过是body标签的底部添加。



营业执照
seo合集软著
wordpress积木主题软著
报价
交流
微信二维码
图片