I have a large amount of posts and some only have one sentence. This means for some posts all the content can be read in an archive without needing to go to the posts single page.
For these posts I want to disable the_permalink in the post’s title. Is there a way I can detect if the excerpt length limit was reached?
Then I can use something like
<a href="<?=($if_has_more_link ? the_permalink() : '#' )?>" ><? the_title(); ?></a>
We need two functions in the themeâs
functions.php
:TRUE
.Letâs start with the first function. This is rather simple because we solved that already. 🙂
The second function will replace the excerpt with the full content conditionally:
Whenever you call
the_excerpt()
in your theme this function will filter it and return the full formatted content if this is not longer than the excerpt would be.Now to your initial question: changing the title. We will just reuse the function
is_short_content()
for that:Note how I put the markup into the
the_title()
function: If a post has no title, we donât want to see an empty<h2>
. And I removed the link completely, because<a href="#">
is a terrible user experience. 🙂As a last note: Do not use just
<?
to open a PHP context. Short open tags are disabled in many environments because they break XML output.