Inside my loop, I'm trying to have a link show and it won't I'm not sure why

Here is the code:

<?php the_title('<h2 class="wow"><a href="<?php the_permalink(); ?>"', '</a></h2>'); ?>

I understand this is maybe because of the '' quotations instead of "", but how would I achieve this general thing with just PHP and not by wrapping the_title(); in an a tag.

up vote 2 down vote accepted

because the_title() expects a string for the $before and $after args, you need to use the string version of the permalink, in a string concatenation;

<?php the_title('<h2 class="wow"><a href="'.get_permalink().'">', '</a></h2>'); ?>

you also had a missing >.

https://developer.wordpress.org/reference/functions/get_permalink/

  • I eventually found the answer elsewhere. THANK YOU. This is pretty much what the answer said to do. The only difference was that it escaped the permalink instead. – Frank Play Sep 27 '17 at 22:48

You can't nest these functions. Change your code to

<h2 class="wow"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

23 seconds too late.

I think the issue is that you have a double open/close statement.

Without seeing your code, I would suggest you to edit your line of code as

<h2 class="wow"><a href="<?php the_permalink(); ?>"><?php echo get_the_title(); ?></a></h2>

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.