如何使用插件在每个wordpress页面上显示相同的文本数据

时间:2018-02-12 12:20:00

标签: wordpress wordpress-theming wordpress-hook

我希望使用插件将页面标题后的“Hello World”打印到每个wordpress页面。我可以从主题文件夹中的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');
?>

1 个答案:

答案 0 :(得分: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');
相关问题