php the title,php-如何在wordpress the_title中替换文本?

我想替换wp title中的文本,

实际上,有一个用于热门帖子的小部件.我想替换此窗口小部件的输出中的文本,因此我环顾了窗口小部件的功能,发现以下代码:

foreach($popular as $post) :

setup_postdata($post);

?>

<?php the_post_thumbnail('widgetthumb',array('title' => '')); ?>

blah blah blah...

我试图更改此行至 :

$wptitle = the_title();

$wptitle = str_replace('textbefore', 'textafter', $wptitle);

echo $wptitle;

?>

但是它在实时站点中什么也没做,也没有任何影响!

如何替换小部件输出中标题中的文本?如果要替换两个字符串,怎么可能?

我应该使用这样的东西吗?

$wptitle = the_title();

$wptitle = str_replace('textbefore', 'textafter', $wptitle) && str_replace('text2before', 'text2after', $wptitle);

echo $wptitle;

?>

解决方法:

$wptitle = the_title();

$wptitle = str_replace('textbefore', 'textafter', $wptitle);

echo $wptitle;

?>

用…来代替

$wptitle = get_the_title($post->id);

$wptitle = str_replace('textbefore', 'textafter', $wptitle);

echo $wptitle;

?>

标签:wordpress-theming,wordpress-plugin,wordpress,php

来源: https://codeday.me/bug/20191118/2029453.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值