![](/img/trans.png)
[英]How can I get value from a custom field in body of a page, then put it in the meta tags content in header? Wordpress
[英]How can I remove tags from content results wordpress?
我正在嘗試通過get_the_excerpt()帶來一些結果。
在某種程度上,我有這樣的結果。 我想刪除結果中的標簽
這是我得到的文本:
板球世界杯優勝者板球世界杯優勝者:AsiaBet.org團隊提供的信息圖將板球世界杯優勝者嵌入您的網站:復制並粘貼以下代碼https://www.asiabet.org/wp-content/uploads /2015/02/CWC_ALL1.jpg” alt =“亞洲板球世界杯冠軍– Asiabet.org”> https://www.asiabet.org/cricket-world-cup-infographic/“>亞洲板球世界杯冠軍2015年只意味着一件事– ICC板球世界...
我的密碼
$result = get_the_excerpt();
if ($result != '') {
echo $result . '...'.'<br><br>';
} else {
$post_id = get_the_ID();
echo get_post_field('description', $post_id);
} ?>
preg_replace('/\\[.*.\\]/', '', 'Cricket World Cup Winners [Info-graphic] [hupso] Cricket World Cup Winners : An info-graphic by the team at AsiaBet.org Embed Cricket World Cup Winners on Your Site: Copy and Paste the Code Below Cricket World Cup Winners by Asiabet.org 2015 only means one thing – the ICC Cricket', -1, $count);
您可以使用strip_shortcodes($ result);
您可以使用以下內容:
$result= strip_tags(get_the_excerpt());
$find = array('/\\[.*.\\]/', '/[a-zA-Z]*[:\/\/]*[A-Za-z0-9\-_]+\.+[A-Za-z0-9\.\/%&=\?\-_]+/i','[”]','[alt=Cricket World Cup Winners – >>]');
$result = preg_replace($find, '',$result, -1, $count);
if ($result != '') {
echo $result . '...'.'<br><br>';
} else {
$post_id = get_the_ID();
echo get_post_field('description', $post_id);
}
刪除任何短代碼,例如[Info-graphic]
。 您必須在主題中定義此短代碼,否則它將作為字符串,您可以使用任何php函數(例如str_replace())替換它,可以通過以下步驟添加給定的短代碼:
function shortcode_function( $atts ) {
return "1234567890";
}
add_shortcode( 'Info-graphic', 'shortcode_function' );
$result = 'this is shortcode [Info-graphic]';
strip_shortcodes( $result );
此功能將起作用。
PHP具有內置功能strip_tags 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.