Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.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
WordPress文件中的HTML标记;functions.php“;_Php_Html_Wordpress - Fatal编程技术网

WordPress文件中的HTML标记;functions.php“;

WordPress文件中的HTML标记;functions.php“;,php,html,wordpress,Php,Html,Wordpress,我想在PHP变量中插入一些HTML标记,但它只会产生PHP变量值 它获取the_subtitle()值并将其插入PHP变量,最后将其添加到$content的第一部分。为什么HTML标记不存在 我的代码: add_filter( 'the_content', 'add_before' , 20 ); function add_before($content) { if ( the_subtitle() ){ $custom_content = '<h2 class=

我想在PHP变量中插入一些HTML标记,但它只会产生PHP变量值

它获取
the_subtitle()
值并将其插入PHP变量,最后将其添加到
$content
的第一部分。为什么HTML标记不存在

我的代码:

add_filter( 'the_content', 'add_before' , 20 );

function add_before($content) {
    if ( the_subtitle() ){
        $custom_content = '<h2 class="subtitlessss">' . the_subtitle() . '</h2><br>';
    }
    $content = $custom_content . $content;
    return $content;
}
add_过滤器('the_content','add_before',20);
函数add_before($content){
如果(子标题(){
$custom_content=''。_副标题();
}
$content=$custom_content.$content;
返回$content;
}

您拥有的代码将始终运行此行:

$content = $custom_content . $content;
这可能是问题所在吗?如果_subtitle()返回真值,请仅尝试修改$content,如下所示:

add_filter( 'the_content', 'add_before' , 20 );

function add_before( $content ) {

  if ( the_subtitle() ) {
    $custom_content = '<h2 class="subtitlessss">' . the_subtitle() . '</h2><br>'; 
    $content = $custom_content . $content;
  }

  return $content;
}
搜索字幕()后更新

好的,看来_subtitle()采用了与本机WP函数相同的参数,_title如文档所述:

参数就像WP内置的_title()方法一样, _subtitle()标记接受三个参数:

$before(字符串)要放置在字幕之前的文本。默认为“”

$after(字符串)要放置在字幕后的文本。默认为“”

因此,如果希望HTML出现在_字幕之前和之后,请将其作为参数传递:

the_subtitle( '<h2 class="subtitlessss">','</h2><br>' );
整个摘录的更新代码如下:

<?php

add_filter( 'the_content', 'add_before' , 20 );

function add_before( $content ) {

  if ( function_exists( 'the_subtitle' ) ) {
    $custom_content = the_subtitle( '<h2 class="subtitlessss">','</h2><br>' ); 
    $content = $custom_content . $content;
  }

  return $content;
}

您拥有的代码将始终运行此行:

$content = $custom_content . $content;
这可能是问题所在吗?如果_subtitle()返回真值,请仅尝试修改$content,如下所示:

add_filter( 'the_content', 'add_before' , 20 );

function add_before( $content ) {

  if ( the_subtitle() ) {
    $custom_content = '<h2 class="subtitlessss">' . the_subtitle() . '</h2><br>'; 
    $content = $custom_content . $content;
  }

  return $content;
}
搜索字幕()后更新

好的,看来_subtitle()采用了与本机WP函数相同的参数,_title如文档所述:

参数就像WP内置的_title()方法一样, _subtitle()标记接受三个参数:

$before(字符串)要放置在字幕之前的文本。默认为“”

$after(字符串)要放置在字幕后的文本。默认为“”

因此,如果希望HTML出现在_字幕之前和之后,请将其作为参数传递:

the_subtitle( '<h2 class="subtitlessss">','</h2><br>' );
整个摘录的更新代码如下:

<?php

add_filter( 'the_content', 'add_before' , 20 );

function add_before( $content ) {

  if ( function_exists( 'the_subtitle' ) ) {
    $custom_content = the_subtitle( '<h2 class="subtitlessss">','</h2><br>' ); 
    $content = $custom_content . $content;
  }

  return $content;
}

您正在使用筛选器修改内容()的输出。您的回调应该返回一个值,但是您正在使用的函数将输出您的字幕,而不是返回它

根据插件文档,它的工作方式与WordPress的
标题()
相同。起初我认为
get\u the\u subtitle()
更合适,但事实并非如此。告诉
子标题()
不要输出(第三个参数)

函数在($content)之前添加{
//检查字幕是否已设置,并将值分配给$subtitle
//这样我们就不用再次调用相同的函数了。
如果($subtitle=子标题(“”,
,false)){ //在内容前面加上前缀。 $content=$subtitle.$content; } //始终返回内容。 返回$content; } 添加\u过滤器('the \u content','add \u before',20);
您正在使用筛选器修改内容()的输出。您的回调应该返回一个值,但是您正在使用的函数将输出您的字幕,而不是返回它

根据插件文档,它的工作方式与WordPress的
标题()
相同。起初我认为
get\u the\u subtitle()
更合适,但事实并非如此。告诉
子标题()
不要输出(第三个参数)

函数在($content)之前添加{
//检查字幕是否已设置,并将值分配给$subtitle
//这样我们就不用再次调用相同的函数了。
如果($subtitle=子标题(“”,
,false)){ //在内容前面加上前缀。 $content=$subtitle.$content; } //始终返回内容。 返回$content; } 添加\u过滤器('the \u content','add \u before',20);
您没有显示足够的代码来说明发生了什么。所有的事情是第4行中的标记没有显示在$custom\u content value中…
subtitle()
不是本机WP函数。请发布该函数的代码这是该插件的短代码:您没有显示足够的代码来说明发生了什么。所有的事情是第4行中的标记没有显示在$custom\u content value中…
the\u subtitle()
不是本机WP函数。请发布该函数的代码这是该插件的短代码:_subtitle有一个真值,并显示在结果中,但html标记不显示,我尝试了你的代码,但它不起作用…谢谢,我没有具有_subtitle()函数的插件,所以我只是将其更改为真,并在2017主题上运行良好。我得到了一个元素,有课堂字幕和我编的一些内容。你确定要在这个html显示的页面上调用了_content()吗?这是这个插件的短代码:是的,我确定,因为当我在functions.php中插入这段代码时,子标题值显示在文章上方,当我删除这段代码时,它不会显示,这意味着这段代码正确地检索了字幕,但是我不知道为什么html标签被修剪了…啊,好吧,看起来你需要在函数调用中添加html到_字幕,就像你在本地WP中添加_title函数一样。我会更新我的答案给你看。谢谢,我试过你的代码,但问题已经存在了。。。!html标记仍然没有出现…字幕有一个真值并显示在结果中,但html标记没有显示,我尝试了你的代码,但它不起作用…谢谢,我没有具有字幕()函数的插件,所以我只是将其更改为真,这在2017主题上运行良好。我得到了一个元素,有课堂字幕和我编的一些内容。您确定要在其上显示此html的页面上调用了_content()?这是此插件的短代码:yes i