web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

wordpress如何实现pc端和移动端通用模板

578 ℃
     

wordpress如何做一个简单的pc端和移动端通用模板的网站,下面web建站小编给大家简单介绍一下具体实现方法!

步骤一:wp-config新增以下代码

$current_sitename= $_SERVER['HTTP_HOST'];
if ($current_sitename == "ipkd.cn" || $current_sitename == "www.ipkd.cn") {
  define("WP_SITEURL", "https://www.ipkd.cn");
  define("WP_HOME", "https://www.ipkd.cn");
} elseif ($current_sitename == "m.ipkd.cn") {
  define("WP_SITEURL", "https://m.ipkd.cn");
  define("WP_HOME", "https://m.ipkd.cn");
}

步骤二:模板标题修改

<title><?php wp_title('-',true,'right'); ?><?php
    if(strpos($_SERVER['HTTP_HOST'], 'm.ipkd.cn') !== false){
     echo '手机web建站';}else{echo 'web建站教程'; }
    ?></title>
//所有需要修改的地方都可以根据判断显示

步骤三:判断设备自动跳转

if(window.location.host == 'www.ipkd.cn'){
  if (/Android|webOS|iPhone|iPad|Windows Phone|iPod|BlackBerry|
  SymbianOS|Nokia|Mobile|Opera Mini/i.test(navigator.userAgent)) {
	var siteName = window.location.pathname;
	  try {
	    if (typeof siteName !== "undefined") {
	      window.location.href = "https://m.ipkd.cn" + siteName
	    } 
	  } catch (e) {}
  }
}
if(window.location.host == 'm.ipkd.cn'){
  var reWriteUrl = function(url) {
    if (url) {
      var Splits = url.split("/"),
      siteName = window.location.pathname;
      if (typeof siteName !== "undefined") {
        return "https://www.ipkd.cn" + siteName
      }
    }
  };
  if (!/Android|webOS|iPhone|iPad|Windows Phone|iPod|BlackBerry|
  SymbianOS|Nokia|Mobile|Opera Mini/i.test(navigator.userAgent)) {
    var url = window.location.href;
    var pathname = window.location.pathname;
      try {
        window.location.href = reWriteUrl(url)
      } catch(e) {}
  }
}

wordpress建站如何利用mysql语法批量插入文章

wordpress搭建视频网,视频加载慢怎么解决

wordpress如何实现版本回退

wordpress如何在文章标题上显示置顶标签

wordpress如何在二级目录建站(小编亲测有效)

标签: wordpress多站技巧, wordpress建站

上面是“wordpress如何实现pc端和移动端通用模板”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_3836.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > wordpress
本文共计1317个字,预计阅读时长9分钟
生活小工具,收录了80多款小工具
上一篇: 推荐一个可以查询老黄历的网站,可以根据五行取名!
下一篇: 详细介绍HTTP状态码不同之处的原因(什么原因导致的)
x 打工人ai神器