lizus / wp-seo
use for wp seo
Requires
- php: >=7.0
- lizus/wp-function: dev-main
This package is auto-updated.
Last update: 2025-04-16 22:54:20 UTC
README
集成SEO功能,通过wp_head
输出在页面的<head>区域。需要在页面模板的<head>中添加<?php wp_head(); >
。
定制SEO输出通过在主题包中添加常量的方式,建议新建一个seo.php
并在functions.php
中引入,添加三个数组常量:SEO_TITLE
,SEO_KEYWORDS
,SEO_DESCRIPTION
,使用键值对来分别保存页面判断和模板字符串,页面判断可用值如下:
is_home
- 表示首页模板is_search
- 表示搜索页is_archive
- 表示归档页is_date
- 表示日期归档页is_author
- 表示作者归档页is_post_type_archive
- 表示文章归档页is_{post_type}_archive
- 表示某一文章类型归档页,具体值示例: is_post_archiveis_category
- 表示分类列表页is_post_tag
- 表示标签列表页is_tax
- 表示自定义类目列表页is_{tax}
- 表示某一自定义类目列表页is_term_{term_id}
- 表示某一具体类目列表页is_singular
- 表示文章页is_singular_{post_type}
- 表示某类型文章页is_singular_{ID}
- 表示具体某文章页
模板可用标签
%site-name%
- 网站名称 <通用>%site-description%
- 网站副标题 <通用>%author%
- 作者 <仅作者页>%search%
- 搜索词 <仅搜索页>%date%
- 日期时间 <仅日期归档页>%term-name%
- 类目名称 <仅类目列表页>%term-description%
- 类目描述 <仅类目列表页>%post-title%
- 文章标题 <仅文章页>%post-keywords%
- 文章关键词,默认使用文章标签 <仅文章页>%post-excerpt%
- 文章摘要 <仅文章页>%post-author%
- 文章作者 <仅文章页>
常量表 - 最晚可以在主题包的functions.php中定义
SEO_TITLE
: <array> - seo用标题模板,使用键值对,键为页面判断,如:is_home,is_singular,is_term_13,is_singular_1,值为模板,下同SEO_KEYWORDS
: <array> - seo用关键词模板SEO_DESCRIPTION
: <array> - seo用页面描述模板
支持的filter
要注意的是,v_title,v_keywords,v_description这三个filter的执行通常会晚于模板标签解析。
add_filter('seo_resolve_format',fn($str))
- 添加模板可用标签解析,回调函数传入一个参数为需要解析的文本字符串,执行完后返回解析后的字符串即可add_filter('v_title',fn($str))
- seo titleadd_filter('v_keywords',fn($str))
- seo keywordsadd_filter('v_description',fn($str))
- seo descriptionadd_filter('v_og',fn($og))
- 添加og标签,og的传值为键值对数组https://ogp.me/ 示例: $og=[ 'title'=>'', 'url'=>'', 'description'=>'', 'type'=>'', 'site_name'=>'', 'image'=>'', 'image:secure_url'=>'', 'image:alt'=>'', 'article:published_time'=>get_the_time('Y-m-d H:i:s'), 'article:author'=>'', ];