如何在元素之后添加代码?

时间:2018-05-20 19:29:48

标签: php html wordpress

我创建了一个非常简单的插件,可以为已安装的wordpress主题添加一些自定义代码,它在顶部包含一些信息:

if ( ! defined( 'ABSPATH' ) ) exit;

echo '<style>.test{background:#000;color:#fff}</style>';
echo '<h1 class="test">Testing</h1>';

如果管理员已登录,我想在<body>之前添加该代码,除了顶部的wordpress管理菜单之外的任何其他元素,以便代码不会隐藏在该菜单下面。< / p>

所以网站上的每个页面都是这样的:

<!DOCTYPE html>
<html>
    <head>
        //Some Code
    </head>
    <body>
        //WP Admin Menu If An Admin Is Logged In
        //My Custom Code Goes Here
    </body>
</html>

1 个答案:

答案 0 :(得分:-1)

请在https://wordpress.stackexchange.com中发布与WordPress相关的查询,而不是在StackOverflow中发布。

add_action('wp_head', 'wpse_43672_wp_head');
function wpse_43672_wp_head(){
    //Close PHP tags 
    ?>
    ADD YOUR PLAIN HTML CODE HERE
    <?php //Open PHP tags
}