当前位置:网站首页>WordPress adds article topping, password protection, and privacy Tags
WordPress adds article topping, password protection, and privacy Tags
2022-06-29 07:06:00 【Dream not】
I want to give WordPress Article add top 、 Password protection 、 A private mark , To make it easy to identify , And there are two ways
- Display as a prefix to the article title
- Display individually
Display as a prefix to the article title
We know ,WordPress Password protected articles will be given by default 、 Private articles add “ Password protection :” and “ Private :” Title prefix of
But for the top article , There is no default title prefix

If you want to customize password protection and the title prefix of private articles
First find... On the server WordPress Site directory , As the author said /www/wwwroot/[ Site file name ]
Find... Under the directory wp-content/themes/[WordPress Subject name used ]/functions.php
Add the following functions to it ,return In the sentence %s The previous content is your custom content
add_filter( 'protected_title_format', 'zhang_protected_title_format' );
// Password protected article title prefix
function zhang_protected_title_format( $format ) {
return '<span class="protected-tag"> Password protection </span>%s';
}
add_filter( 'private_title_format', 'zhang_private_title_format' );
// Private article title prefix
function zhang_private_title_format( $format ) {
return '<span class="private-tag"> Private </span>%s';
}
Simply add CSS style
/* Top mark */
.sticky-tag{
color:#FFF;
background:#A0CCEB;
border-radius:0.5em;
padding:0.1em 0.4em;
font-size:0.9em;
margin-right:1em;
}
/* Password protected mark */
.protected-tag{
color:#FFF;
background:#FECB97;
border-radius:0.5em;
padding:0.1em 0.4em;
font-size:0.9em;
margin-right:1em;
}
/* Private mark */
.private-tag{
color:#FFF;
background:#FC8893;
border-radius:0.5em;
padding:0.1em 0.4em;
font-size:0.9em;
margin-right:1em;
}
The following effects can be achieved

Display individually
If you want to display the tag separately , It is necessary to judge the type of articles , Here is the top of the judgment article 、 Password protection 、 Private correlation functions
is_sticky();
// Judge whether the article is at the top , The top of the article is true, Do not set the top for false
post_password_required();
// Determine whether the article needs a password , If the article has a password and the password has not been entered yet, it is true, The article has no password or the password entered is false
get_post_status();
// Query article status
// 'publish' – Published articles or pages
// 'pending' – Articles to be reviewed
// 'draft' – draft
// 'auto-draft' – Save drafts automatically
// 'future' – Scheduled release
// 'private' – Private articles
// 'inherit' – Revision
// 'trash' – In the recycle bin
Find the blog post list page file :wp-content/themes/[WordPress Subject name used ]/content.php, And add the following code where you think it's appropriate
<?php if( is_sticky() ) echo '<span class="sticky-tag"> Roof placement </span>'; ?>
<?php if( post_password_required() ) echo '<span class="protected-tag"> Password protection </span>'; ?>
<?php if( get_post_status()=='private' ) echo '<span class="private-tag"> Private </span>'; ?>
Add... As in the previous method CSS style
/* Top mark */
.sticky-tag{
color:#FFF;
background:#A0CCEB;
border-radius:0.5em;
padding:0.1em 0.4em;
font-size:0.9em;
margin-right:1em;
}
/* Password protected mark */
.protected-tag{
color:#FFF;
background:#FECB97;
border-radius:0.5em;
padding:0.1em 0.4em;
font-size:0.9em;
margin-right:1em;
}
/* Private mark */
.private-tag{
color:#FFF;
background:#FC8893;
border-radius:0.5em;
padding:0.1em 0.4em;
font-size:0.9em;
margin-right:1em;
}
Then you can present the following effects

边栏推荐
- 关于DDNS
- Ribbon 服务调用与负载均衡
- Mongostat performance analysis
- idea控台中文乱码问题【亲测有效】
- Delete tag
- QT program packaging and publishing windeployqt tool
- Idea integrated code cloud
- . Net core + DDD basic layering + project basic framework + personal summary "suggestions collection"
- Chapter IV introduction to FPGA development platform
- JDBC connects to the database and socket sends the client.
猜你喜欢

json tobean

Annual inventory review of Alibaba cloud's observable practices in 2021

How does schedulerx help users solve distributed task scheduling problems?

Qt 串口编程

Yyds dry goods inventory meituan's two-sided experience, and finally there was a surprise?

In vscade, how to use eslint to lint and format

QT qlineedit details

Delete tag

Baidu applet automatically submits search

json tobean
随机推荐
Service grid ASM year end summary: how do end users use the service grid?
package.json的所有配置项及其用法,你都熟悉么
多模态 —— Learnable pooling with Context Gating for video classification
Li Kou daily question - day 30 -1281 Difference of sum of bit product of integer
Creating a new generation of production and service tools with robot education
Draw multiple ROC curves on a graph
Better than postman! Apipost knows more about Chinese programmers! How delicious!
Differences between JSON objects and JSON strings
Yyds dry goods inventory meituan's two-sided experience, and finally there was a surprise?
Class differences of QT processing image data (qpixmap, qimage, qpicture)
QT custom bit operation class
Antd work item memo w3.0
Presto-Trial
Output of character pointer to string in C language
Domestic code hosting center code cloud
NoSQL数据库之Redis(五):Redis_Jedis_测试
Ci tool Jenkins II: build a simple CI project
C language pointer to function
数据库-同义词
try anbox (by quqi99)