shortcode – Trying do_shortcode inside template file but need php inside do_shortcode-ThrowExceptions

Exception or error:

i have a php template for a posts archive and that is the part

<h3 class="entry-title mh-posts-grid-title">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark">   
<?php the_title(); ?>
</a>
</h3>

Now i want to use this inside a shortcode and i tried it only with the part of the_title();

I tried several solutions i found here. When i try it with simple html instead of the_title() it works, but as soon as i try it with the_title i get errors or the title doesn’t appear. I need enclosing shortcodes

What i tried

<?php echo do_shortcode( '[um_loggedin] $the_title [/um_loggedin]' );?
<?php echo do_shortcode( '[um_loggedin] $the_title() [/um_loggedin]' );?
<?php echo do_shortcode( '[um_loggedin] $the_title(); [/um_loggedin]' );?

Same without $

Thanks for any help 🙁

How to solve:

Now i have found the solution myself

echo do_shortcode('[um_loggedin]'.get_the_title().' [/um_loggedin]');

Leave a Reply

Your email address will not be published. Required fields are marked *