Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 禁用Wordpress短标记_Php_String_Wordpress_Filter_Hook - Fatal编程技术网

Php 禁用Wordpress短标记

Php 禁用Wordpress短标记,php,string,wordpress,filter,hook,Php,String,Wordpress,Filter,Hook,我想修改Wordpress短标记的布局。我想修改的标签是将一篇文章分成多个页面的标签 在我的主题中,我需要禁用该功能并将每个部分包装在一个div中 我知道可以添加过滤器来修改短标签,但显然我做错了什么。下面的函数似乎没有替换短标记,我仍然得到一个分页列表 有人能提出一个替代短标签的解决方案吗 add_filter( 'the_content', 'reformat_lists' ); function reformat_lists($content){ $f = '<!--nex

我想修改Wordpress短标记的布局。我想修改的标签是将一篇文章分成多个页面的标签

在我的主题中,我需要禁用该功能并将每个部分包装在一个div中

我知道可以添加过滤器来修改短标签,但显然我做错了什么。下面的函数似乎没有替换短标记,我仍然得到一个分页列表

有人能提出一个替代短标签的解决方案吗

add_filter( 'the_content', 'reformat_lists' );

function reformat_lists($content){
    $f = '<!--nextpage-->';
    $r = '<div id="cmn-list">';
    str_replace($f,$r,$content);
    return $content;
}
add_filter('the_content','reformat_list');
函数重新格式化\u列表($content){
$f='';
$r='';
str_替换($f,$r,$content);
返回$content;
}

您的post查询可能正在调用
设置\u postdata
,因此在您有机会之前,
已经被替换,因此您可能需要使用另一个筛选器或找出Wordpress正在插入的内容。如果使用而不是
WP\u查询
,则可以在
setup\u postdata
之前获取内容。理想情况下,您可以在之前发生的内容上找到一个过滤器,但不是在DB写入之前,但我似乎找不到任何可以做这项工作的东西

它并不美观,因为它具有破坏性(在保存到数据库之前替换标记),而不仅仅是在打印之前,但这可能适合您:

function reformat_lists($content){
    $f = '<!--nextpage-->';
    $r = '<div id="cmn-list">';
    $content = str_ireplace($f,$r,$content); //don't forget to pass your replaced string to $content
    return $content;
}
add_filter( 'content_save_pre', 'reformat_lists');
function reformat_lists($content){
    global $post;
    $content = $post->post_content;
    $f = '<!--nextpage-->';
    $r = '<div id="cmn-list">';
    $content = str_ireplace($f,$r,$content) . '</div>';
    return $content;
}
add_filter( 'the_content', 'reformat_lists', 1);