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:
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?
the_title() function display the title, to return it you have to use the_title(”,”,false) or get_the_title() .
see doc: http://codex.wordpress.org/Function_Reference/the_title