Wordpress 主题提醒用户安装一个插件

in functions.php: /* check required plugins */ add_action( 'admin_notices', 'dukeyin_theme_dependencies' ); function dukeyin_theme_dependencies() { if( ! function_exists('new_cmb2_box') ) echo '<div class="notice notice-error"><p>' . __( '<h4>Warning: Plugin Missing: CMB2</h4>The DukeYin theme needs Plugin <a href="https://wordpress.org/plugins/cmb2/" target="_blank">CMB2</a> to function. Search "CMB2" in wordpress plugin panel, install and activit it.', 'dukeyin' ) . '</p></div>'; if(!function_exists('simpleYearlyArchive')) echo '<div class="notice notice-warning"><p>' . __( '<h4>Notice: Plugin Missing: Simple Yearly Archive</h4>The DukeYin theme needs Plugin <a href="https://wordpress.org/plugins/simple-yearly-archive/" target="_blank">Simple Yearly Archive</a> to display the archive page. Search "Simple Yearly Archive" in wordpress plugin panel, install and activit it to make your site better.', 'dukeyin' ) . '</p></div>'; }   ...

2018-07-30 · 1 min · Duke Yin

全站改https的方法

如今个人ssl证书已经很便宜,很多商家甚至提供免费的ssl证书,如何让我们的网站获得全站ssl证书? 网站配置文件中开放443端口 填写获得的ssl密钥文件地址 Wordpress设置中修改主站地址为https 在数据库中替换所有图片以及其他附件地址为https UPDATE wp_posts SET post_content = replace(post_content, 'http://www.domain.com/wp-content/uploads','https://www.domain.com/wp-content/uploads'); 如果你不太会使用mysql命令,还可以在主题的functions.php中添加如下代码以达到附件地址替换为https /* 替换图片链接为 https */ function my_content_manipulator($content){ if( is_ssl() ){ $content = str_replace('http://www.domain.com/wp-content/uploads', 'https://www.domain.com/wp-content/uploads', $content); } return $content; } add_filter('the_content', 'my_content_manipulator'); 强制后台使用https 在wp-cofig 文件中加入如下条目 /* 强制后台和登录使用 SSL */ define('FORCE_SSL_LOGIN', true); define('FORCE_SSL_ADMIN', true); 由于https要求全部外链文件都必须是https,所有如果之前主题引用了http的资源,比如logo图片地址,jQ文件或者其他js,记得要替换引用的地址为https,尽量放本地加载。 ...

2017-06-15 · 1 min · Duke Yin

Disable s.w.org dns prefetch and emoji

Put these into functions.php in your wordpress theme. //disable sworg dns-prefetch function remove_dns_prefetch( $hints, $relation_type ) { if ( 'dns-prefetch' === $relation_type ) { return array_diff( wp_dependencies_unique_hosts(), $hints ); } return $hints; } add_filter( 'wp_resource_hints', 'remove_dns_prefetch', 10, 2 ); //Disable the emoji's remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'wp_print_styles', 'print_emoji_styles' ); add_filter( 'emoji_svg_url', '__return_false' );

2016-11-26 · 1 min · Duke Yin

错误:不需要升级 您的wordpress数据库已经是最新的了

有天打开Wordpress后台后自动跳转到升级页,提示: “不需要升级 您的wordpress数据库已经是最新的了” 无论访问后台的哪个页,都会跳转到这个提示,点继续依然还是回到这里死循环。 一查是我在服务器装了Memcached缓存,极可能是缓存把更新页数据当成缓存存起来了,所以必须要先清空缓存,然后才能进后台。 两种方法, 第一种是直接连Linux管理终端 telnet localhost 11211 flush_all 即可 第二种,先把Wordpress的wp-content下的object-cache.php重命名成其他名字,现在发现可以进后台了;紧接着安装WP Memcached Manager 插件,配置好Memcached服务器IP(自己服务器的内网IP即可),然后Flush memcache一下,再把刚刚重命名的文件还原成object-cache.php,问题就解决了。

2015-07-24 · 1 min · Duke Yin

Wordpress后台评论IP地址不正确的解决方法

概要 标签提供关于HTML文档的元数据。元数据不会显示在页面上,但是对于机器是可读的。它可用于浏览器(如何显示内容或重新加载页面),搜索引擎(关键词),或其他 web 服务。 必要属性 属性 值 描述 content some text 定义与http-equiv或name属性相关的元信息 可选属性 属性 值 描述 http-equiv content-type / expire / refresh / set-cookie 把content属性关联到HTTP头部。 name author / description / keywords / generator / revised / others 把 content 属性关联到一个名称。 content some text 定义用于翻译 content 属性值的格式。 SEO优化 ...

2015-06-17 · 2 min · Duke Yin

Woredpress用TimThumb或七牛裁剪特色图像

Wordpress虽然内置图片裁剪功能,但只能固定设置“Thumbnail” “Medium” “Large”三种尺寸,在很多时候并不能满足网站主题显示图像的需求,所以TimThumb这个项目就是为了解决这一问题,只要在URL中设定需要显示的缩略图尺寸,就能很快得到需要的缩略图,我在这篇文章中介绍了如何使用TimThumb.php。 文章“特色图像”是一篇文章的题图,不同环境需要输出不同图片尺寸,比如列表的图片需要小一点,文章页的图片又需要大一点,手机界面的又需要更小,我之前的文章已经介绍过关于获取特色图像的方法。结合TimThumb和获取到的特色图像,以下给出代码,用TimThumb来输出自定义尺寸的特色图像,655宽268高,并且链接到原图。 <!-- get preview image --> <!--?php if ( has_post_thumbnail()):?--> <a href="<?php $array_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post-&gt;ID), array(770,770)); echo $array_image_url[0]; ?>;"> <img src="<?php echo get_stylesheet_directory_uri() ?&gt;/timthumb.php?src=&lt;?php $array_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post-&gt;ID), array(770,770)); echo $array_image_url[0]; ?>&h=268&w=655&zc=1" alt="<?php the_title() ?>" /></a> <!--?php endif; ?--> <!-- get preview image end-->   ...

2015-02-17 · 1 min · Duke Yin

使用wp_update_post代替wp_publish_post

最近制作Keep Minutes网站的时候,遇到一个问题: 前端发布理所应当使用wp_insert_post(),但是同时需要将经纬度地理信息也一并添加进日志meta信息,如果wp_insert_post()里的array设为'post_status' => 'publish',则可能会造成来不及将meta信息添加好,文章就发布了,meta信息就添加失败。所以只能先存一个草稿。 解决:使用wp_insert_post()创建一篇草稿(draft),添加上一些meta信息,并紧接着使用wp_publish_post()试图将这篇“草稿文章”发布出来 $post_id = wp_insert_post( array( 'post_author' => $user_id, 'post_title' => wp_strip_all_tags($post_content), 'post_content' => $post_content, 'tags_input' => strip_tags($tags), 'post_status' => 'draft' ) ); add_post_meta($post_id, 'address', $address, true); wp_publish_post( $post_id ); 这倒是解决了meta信息添加失败的问题,但新的问题又来了,这样发布的文章缺失slug和时间日期,其原因是wp_publish_post()除了将文章状态由“草稿”改为“已发布”,并没有额外的操作,缺失了文章数据。 解决:使用使用wp_update_post代替wp_publish_post 把 wp_publish_post( $post_id ); 改为 ...

2015-02-09 · 1 min · Duke Yin

解决VPS中Wordpress更新或上传需要FTP账号密码

将以下添加到“wp-config.php” /** 解决更新需要FTP。 */ putenv('TMPDIR=' . ini_get('upload_tmp_dir')); if(is_admin()) { add_filter('filesystem_method', create_function('$a', 'return "direct";' )); define( 'FS_CHMOD_DIR', 0751 ); }

2014-12-31 · 1 min · Duke Yin

PHPMyadmin 常用SQL命令 不断更新

常用操作 将 field1的内容拷贝到field2覆盖: UPDATE 表名 SET 字段= REPLACE(字段,'查找内容','替换内容'); 例如: UPDATE wp_postmeta SET meta_value = REPLACE(meta_value,'old','new'); 在wp_postmeta表搜索meta_value中包含 old 的项,把old替换为 new,使用WHERE可以指定特定的项: 修改站点url: UPDATE wp_options SET option_value = replace(option_value, 'http://old.com','http://new.com') WHERE option_name = 'home' OR option_name = 'siteurl'; 修改文章中内部链接及附件的地址: ...

2014-11-13 · 2 min · Duke Yin

Wordpress PHP简单方法输出多栏布局元素类

经常会遇到如上图一样的布局,有时候三列有时候四列,如果是静态页面,一般处理方法是在一列的最后一个元素加一个类class,然后针对这个类写CSS。 但是如果在Wordpress的loop里,通常所有的日志“块”代码都是一样的,如何判断某个元素是一行的最后一个然后加入代码呢? 这个问题困扰了我几个小时。本来有一个已经解决好了的范本,但是太过于复杂,后来我解决了,还算比较简洁,现公布如下: 先在Loop中让一个变量自己增加-> <?php $additional_loop = new WP_Query($query_string); if ($additional_loop->have_posts()) : while ($additional_loop->have_posts()) : $additional_loop->the_post(); $count++; ?>   ...

2014-10-16 · 1 min · Duke Yin