在循环中显示不必要的链接文本的固定链接短代码

时间:2021-06-15 作者:GOST

最近我需要有关permalink短代码的帮助

function my_permalink(){
ob_start();
the_permalink();
return ob_get_flush();}

add_shortcode(\'my_permalink\',\'my_permalink\');
为此,我得到了一个短代码[我的permalink],它工作得很好

But the problem is when I use this shortcode on my WordPress Posts, Pages, CPT, CT or any custom Archive Page it shows me some unnecessary link text which is at top of the loop and also it does not include any HTML tag

我正在显示截图和帖子中出现的链接位置

代码:

    </div>
        <div class="entry-content">
            https://careerfeed.net/jobs/kfri-recruitment-2021-for-1-project-assistant/<div class="wprt-container"><p>KFRI Recruitment 2021 for 1 Project Assistant Applications are invited from eligible candidates for the post of one <b>Project Assistant </b>under the project KFRI/RP 823/2021 entitled “Ecological studies on post restoration success of threatened plants in situ.&#8221;</p>
https://careerfeed.net/jobs/kfri-recruitment-2021-for-1-project-assistant/
<p>&nbsp;</p>
屏幕截图:URL显示:

https://prnt.sc/15jcg6d

我只是粘贴了短代码:

https://prnt.sc/15jckza

内部检查元件:

https://prnt.sc/15jct1q

1 个回复
SO网友:Tom J Nowell

ob_get_flush 不会做你认为它会做的事。假设它只结束输出缓冲区并返回其内容,这是不正确的,它还会将输出缓冲区刷新到浏览器。

因此:

return ob_get_flush();
与此相同:

$content = ob_get_clean();
echo $content;
return $content;
使用ob_get_clean(); 相反,这会擦除输出缓冲区,而不是刷新它。

相关推荐

List categories with posts

我知道我可以用wp_list_categories() 列出类别,但我如何才能同时列出各个类别下的帖子,下面是我想要实现的示例:类别1——cat1下的职位——cat1下的职位——cat2下的职位