sanitize the_title() in wordpress posts loop

i am using a while loop in wordpress and i want to create my own link to a post:

<?php $query = new WP_Query( array('post_type' => 'knowledgebase', 'posts_per_page' => 20, 'knowledgebase-categories' => $var_id ) ); ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<a href="/knowledgebase/article/"><?php sanitize_title(the_title()); ?></a>
</article> <!-- .et_pb_post -->
<?php endwhile; ?>

i am trying to sanitize the title of each post using:

Read More
sanitize_title(the_title());

but its just not changing it at all.

if i do a: var_dump(sanitize_title(the_title()));

it jsut returns string(0) ""

how can i sanitize the title (the_title()) in my wordpress/php code?

Related posts

1 comment

Comments are closed.