admin管理员组文章数量:1335160
I want to add_filter for the_content in functions.php of my theme. I have added code which just display echo but it seams that my filter is not applied.
function add_mod_hatom_data($content) {
// $t = get_the_modified_time('F jS, Y');
//$author = get_the_author();
// $title = get_the_title();
//if(is_single()) {
echo 'perrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr';
// $content .= '<div class="hatom-extra"><span class="entry-title">'.$title.'</span> was last modified: <span class="updated"> '.
//$t.'</span> by <span class="author vcard"><span class="fn">'.$author.'</span></span></div>';
// }
return $content;
}
add_filter('the_content', 'add_mod_hatom_data');
I have tried to call it like this :
add_filter('the_content', 'add_mod_hatom_data', 99);
or change position to be on top of functions.php with no success.
Do I need to enable somewhere add_filter or it is overridden by some other function ? NOTE: In my single post template I have :
<?php get_header(); ?>
<div id="content" class="clearfix row">
<div id="main" class="col-sm-8 clearfix" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article" itemscope itemtype="">
<header>
<div class="page-header clip_content single-post">
<div class="page-header">
<h1 class="single-title-wg" itemprop="headline">
<?php $category = get_the_category();
if ($category[0]) {
echo '<b>'.$category[0]->cat_name.' '.$post->ID.'</b>';
}
?>
</h1>
<h4 class="single-title" itemprop="headline">
<p class="lead">
<?php the_title(); ?>
</p>
</h4>
</div>
<div class="item_footer">
</div>
<?php $category = get_the_category();
if ($category[0]) {?>
<p class="authorParagraph">
<?php echo '<a href="' . get_category_link($category[0]->term_id) . '" class="clearfix">' . $category[0]->cat_name . '</a></p>';
}
?>
</div>
</div>
</header> <!-- end article header -->
<footer>
<!-- <?php the_tags('<p class="tags"><span class="tags-title">' . __("Tags","wpbootstrap") . ':</span> ', ' ', '</p>'); ?> -->
</footer> <!-- end article footer -->
</article> <!-- end article -->
<?php endwhile; ?>
<?php else : ?>
<article id="post-not-found">
<header>
<h1><?php _e("Not Found", "wpbootstrap"); ?></h1>
</header>
<section class="post_content">
<p><?php _e("Sorry, but the requested resource was not found on this site.", "wpbootstrap"); ?></p>
</section>
<footer>
</footer>
</article>
<?php endif; ?>
</div> <!-- end #main -->
</div> <!-- end #content -->
<?php get_footer(); ?>
I want to add_filter for the_content in functions.php of my theme. I have added code which just display echo but it seams that my filter is not applied.
function add_mod_hatom_data($content) {
// $t = get_the_modified_time('F jS, Y');
//$author = get_the_author();
// $title = get_the_title();
//if(is_single()) {
echo 'perrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr';
// $content .= '<div class="hatom-extra"><span class="entry-title">'.$title.'</span> was last modified: <span class="updated"> '.
//$t.'</span> by <span class="author vcard"><span class="fn">'.$author.'</span></span></div>';
// }
return $content;
}
add_filter('the_content', 'add_mod_hatom_data');
I have tried to call it like this :
add_filter('the_content', 'add_mod_hatom_data', 99);
or change position to be on top of functions.php with no success.
Do I need to enable somewhere add_filter or it is overridden by some other function ? NOTE: In my single post template I have :
<?php get_header(); ?>
<div id="content" class="clearfix row">
<div id="main" class="col-sm-8 clearfix" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article" itemscope itemtype="http://schema/BlogPosting">
<header>
<div class="page-header clip_content single-post">
<div class="page-header">
<h1 class="single-title-wg" itemprop="headline">
<?php $category = get_the_category();
if ($category[0]) {
echo '<b>'.$category[0]->cat_name.' '.$post->ID.'</b>';
}
?>
</h1>
<h4 class="single-title" itemprop="headline">
<p class="lead">
<?php the_title(); ?>
</p>
</h4>
</div>
<div class="item_footer">
</div>
<?php $category = get_the_category();
if ($category[0]) {?>
<p class="authorParagraph">
<?php echo '<a href="' . get_category_link($category[0]->term_id) . '" class="clearfix">' . $category[0]->cat_name . '</a></p>';
}
?>
</div>
</div>
</header> <!-- end article header -->
<footer>
<!-- <?php the_tags('<p class="tags"><span class="tags-title">' . __("Tags","wpbootstrap") . ':</span> ', ' ', '</p>'); ?> -->
</footer> <!-- end article footer -->
</article> <!-- end article -->
<?php endwhile; ?>
<?php else : ?>
<article id="post-not-found">
<header>
<h1><?php _e("Not Found", "wpbootstrap"); ?></h1>
</header>
<section class="post_content">
<p><?php _e("Sorry, but the requested resource was not found on this site.", "wpbootstrap"); ?></p>
</section>
<footer>
</footer>
</article>
<?php endif; ?>
</div> <!-- end #main -->
</div> <!-- end #content -->
<?php get_footer(); ?>
Share
Improve this question
edited May 21, 2014 at 10:09
Radenko Zec
asked May 21, 2014 at 7:29
Radenko ZecRadenko Zec
711 gold badge1 silver badge9 bronze badges
4
|
3 Answers
Reset to default 1This part of the single post template is called the loop:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
Within the loop you need to call in the content:
<?php the_content(); ?>
Replace your single post template with this and see if it works now:
<?php get_header(); ?>
<div id="content" class="clearfix row">
<div id="main" class="col-sm-8 clearfix" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article" itemscope itemtype="http://schema/BlogPosting">
<header>
<div class="page-header clip_content single-post">
<div class="page-header">
<h1 class="single-title-wg" itemprop="headline">
<?php $category = get_the_category();
if ($category[0]) {
echo '<b>'.$category[0]->cat_name.' '.$post->ID.'</b>';
}
?>
</h1>
<h4 class="single-title" itemprop="headline">
<p class="lead"> <?php the_title(); ?></p></h4>
<p><?php the_content(); ?></p>
</div>
<div class="item_footer">
</div>
<?php $category = get_the_category();
if ($category[0]) {?>
<p class="authorParagraph">
<?php echo '<a href="' . get_category_link($category[0]->term_id) . '" class="clearfix">' . $category[0]->cat_name . '</a></p>';
}
?>
</div>
</div>
</header> <!-- end article header -->
<footer>
<!-- <?php the_tags('<p class="tags"><span class="tags-title">' . __("Tags","wpbootstrap") . ':</span> ', ' ', '</p>'); ?> -->
</footer> <!-- end article footer -->
</article> <!-- end article -->
<?php endwhile; ?>
<?php else : ?>
<article id="post-not-found">
<header>
<h1><?php _e("Not Found", "wpbootstrap"); ?></h1>
</header>
<section class="post_content">
<p><?php _e("Sorry, but the requested resource was not found on this site.", "wpbootstrap"); ?></p>
</section>
<footer>
</footer>
</article>
<?php endif; ?>
</div> <!-- end #main -->
</div> <!-- end #content -->
<?php get_footer(); ?>
That is because the variable '$content' is empty. The way you are using this filter is correct. Instead of 'echo' put your values in the '$content variable' and then the 'return $content' will in effect echo this out to the page. Try this:
function add_mod_hatom_data($content) {
// $t = get_the_modified_time('F jS, Y');
//$author = get_the_author();
// $title = get_the_title();
//if(is_single()) {
$content = 'perrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr';
// $content .= '<div class="hatom-extra"><span class="entry-title">'.$title.'</span> was last modified: <span class="updated"> '.
//$t.'</span> by <span class="author vcard"><span class="fn">'.$author.'</span></span></div>';
// }
return $content;
}
add_filter('the_content', 'add_mod_hatom_data');
Use this (the_content filter has only one parameter and you must use 1)
add_filter('the_content', 'add_mod_hatom_data', 1);
本文标签: pluginsaddfilter thecontent in functionsphp not working
版权声明:本文标题:plugins - add_filter the_content in functions.php not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742246118a2439616.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
the_content()
to get the content on front end? If not, then is it not possible to fire to this hook. Maybe you must enhance your solution for output the content viaapply_filter
. See also the documentation of the hook. – bueltge Commented May 21, 2014 at 8:17return 'rrr'.$content;
– Michael Commented May 21, 2014 at 8:28