Wordpress Technology

Wordpress Tips, Tutorials, Hacks

Recently I had a task to cut off the piece of content from the post displaing on front page. To resolve it, the wordpress function get_the_content() is defined.

In order to fully undestand what we are talking about, review next code:

$content = get_the_content();
$content = preg_replace('/cut of the content /i', '', $content);
echo $content; // выводим отфильтрованный контент.

Using this method the html tags, which presented in original code, are deleted.

To achieve the desirend result, the next function might be used (must be in functions.php)

function get_the_content_with_formatting ($more_link_text = '') {
	$content = get_the_content($more_link_text);
	$content = apply_filters('the_content', $content);
	// some changes with the $content variable
	echo $content;
}

In the template instead of this code :

<?php the_content('Read more &raquo;'); ?>

we have to use :

<?php get_the_content_with_formatting('Read more &raquo;'); ?>


Both comments and pings are currently closed.

© 2009 | Made by Vancouver Web Design | Internet Marketing