There are a number of problems here, lets go through them one by one
1. Functions that return stuff, and Functions that output stuff
get_the_content
doesn't output anything, it returns it. So you need to echo
it for the results to be visible:
echo get_the_content();
Functions that start with get_
almost always return a value.
Functions that start with the_
almost always output a value, e.g:
the_content();
Which brings us to the next issue:
echo the_title();
This is the same as:
echo '';
the_title();
Functions that return stuff need to either have echo
or they should be assigned to a variable.
This gives us a correct version of what you have that works the same, but minus bugs:
<a href="<?php echo get_the_content(); ?>"><?php the_title(); ?></a>
It still has issues though
2. Security Security Security Security
What happens if your content doesn't contain a link? What if the user put something malicious and nasty in there, or made a typo?
If we apply escaping, we can guarantee it will be a URL:
<a href="<?php echo esc_url( get_the_content() ); ?>"><?php the_title(); ?></a>
It might be a weird garbled URL if malicious stuff got put in there, but it will always be a URL, 100%, guaranteed. That assumption is enforced, and it no longer becomes a matter of "it should be a URL", or "I doubt it'll ever be an issue", instead we now have a cast iron guarantee that it is always a URL
Escaping is one of the biggest security improvements you can make, and fixes a huge number of security issues. Despite this, it's almost always left out of tutorials, ignored by theme developers, and missing from guides themes and products. Escape late, escape often, it'll be a huge boost to your codes security.
3. OEmbed, Gutenberg and Post Formats
What if that URL was an OEmbed value? E.g. a Youtube Video? The editor tries to convert that into a player embed automatically, as will the_content()
, but get_the_content()
won't.
As a result, we're going to need to swap that out, and an <a>
element won't do. Instead, lets simplify this further:
the_content();
For a link post, just use a normal block with a link in it.
4. The Future of Post Formats
Post formats are kept for backwards compatibility, in the future post formats don't make much sense in a block based content world.
E.g. it would be easier to just output a block with a link in it for link posts. Video posts would just be posts that have just a video block, etc
That's the paradigm you should be aiming for, and that's the current thinking of those working on the editor. Post Formats were never really that successful
As useful as youtube guides are, like all articles they become out of date, don't cover everything, and should be taken with a grain of salt. Diversify your research, explore alternative ways to do things, and continue to grow.
That video is just that persons idea of how to do things at that time, but it isn't the only method, or the best. In the future, block based layouts and custom blocks are going to be more useful and flexible than custom page templates, and other older ways of doing things