0

我想使用插件在每个 wordpress 页面的页面标题后打印“Hello World”。我可以从主题文件夹中的 page.php 中做到这一点,但我想使用插件来做到这一点。先感谢您。

<?php
/*
Plugin Name:  Display Data
Plugin URI:   https://rb.com
Description:  My Plugin Dev.
Version:      0.1
Author:       RB
*/
function printData()
{
  if(THIS IS A PAGE)
  {
    echo "Hello World";
  }
  else
  {
    echo "This is not a Page";
  }
}
add_action('DONT KNOW WHAT SHOULD BE HERE','printData');
?>
4

1 回答 1

0

哪里需要打印数据?头衔()?内容标题?

每个页面的标题中的示例:

function printData($title)
{
  if(is_page())
  {
    $title .= " Hello World";
  }
  else
  {
    $title .= " This is not a Page";
  }

  return $title;
}
add_filter('wp_title','printData');

对于内容标题:

function printData($title)
{
  if(is_page())
  {
    $title .= " Hello World";
  }
  else
  {
    $title .= " This is not a Page";
  }

  return $title;
}
add_filter('the_title','printData');
于 2018-02-12T12:32:42.093 回答