【问题标题】:Wordpress: Add Element as a Filter to 'the_content'Wordpress:将元素作为过滤器添加到“the_content”
【发布时间】:2014-02-28 22:28:10
【问题描述】:

我能否以及如何在 function.php 中添加一个过滤器,以便在使用 the_content 时在内容周围添加一个 HTML 元素?这类似于您可以使用 the_title 执行的操作。即:

the_title( '<h1>', '</h1>' );

我需要在内容周围添加一个 section 元素,其中包含类似于以下内容的类:

the_content('<section class="content_wrap">', '</section>');

我知道我可以:

<section class="content_wrap">
    <?php the_content ?>
</section>

但是如果我可以过滤它,它将通过最小化模板文件中的大量代码来大大减少 php 打开和关闭标签的数量 [而且我可以无意识地编写更多代码而无需记住添加标签 - LOL]。

任何帮助将不胜感激。谢谢!

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    你尝试过这样的事情吗?

    function content_filter($content) {
        return '<section class="content_wrap">' . $content . '</section>';
    }
    add_filter( 'the_content', 'content_filter', 6); 
    

    希望对你有帮助:)

    文档:http://wordpress.org/support/topic/add-something-to-the_content

    【讨论】:

    • 我做到了,我想我只是有一个 type-o b4。哈哈,谢谢!
    猜你喜欢
    • 2012-01-22
    • 2013-01-19
    • 2012-11-28
    • 1970-01-01
    • 2013-11-07
    • 2012-05-15
    • 2021-07-09
    • 2011-11-18
    • 2013-06-05
    相关资源
    最近更新 更多