admin管理员组文章数量:1134064
I'm trying to use shortcode in index.php but when I use PHP code in my shortcode, it displays out of shortcode structure.
this HTML code works
<?php echo do_shortcode('[myshortcode label="sample title" Description="Content Goes Here"]'); ?>
this code doesn't work and pushes PHP code out of short code structure
<?php echo do_shortcode('[myshortcode label="'. the_title() .'" Description="Content Goes Here"]'); ?>
it outputs like this:
sample title
<div class="hidden-content">
<span class="show-content"></span>
<div class="showme hidden" style="display: none;">Content Goes Here</div>
</div>
But it must be like this
<div class="hidden-content">
<span class="showcontent">sample title</span>
<div class="showme hidden" style="display: none;">Content Goes Here</div>
</div>
I'm trying to use shortcode in index.php but when I use PHP code in my shortcode, it displays out of shortcode structure.
this HTML code works
<?php echo do_shortcode('[myshortcode label="sample title" Description="Content Goes Here"]'); ?>
this code doesn't work and pushes PHP code out of short code structure
<?php echo do_shortcode('[myshortcode label="'. the_title() .'" Description="Content Goes Here"]'); ?>
it outputs like this:
sample title
<div class="hidden-content">
<span class="show-content"></span>
<div class="showme hidden" style="display: none;">Content Goes Here</div>
</div>
But it must be like this
<div class="hidden-content">
<span class="showcontent">sample title</span>
<div class="showme hidden" style="display: none;">Content Goes Here</div>
</div>
Share
Improve this question
asked Oct 8, 2023 at 1:49
DragutDragut
1732 gold badges2 silver badges11 bronze badges
1 Answer
Reset to default 2You need to change the_title()
to get_the_title()
.
You are asking the shortcode to echo out a string that is returning the title.
It would be good for you to research the difference between the_title
and get_the_title
.
The main difference is that the_title
is actually returning the title without any other requirement (this is simplified: there are filters happening as well) but it is why you see it first before the rest of the code.
本文标签: php codes ruins shortcode structure
版权声明:本文标题:php codes ruins shortcode structure 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736781770a1952638.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论