添加<a> tag using WordPress plugin

时间:2017-02-27 13:45:47

标签: php wordpress

I am learning WordPress and was wondering if it's possible to add HTML code to just above the closing body tag using a WordPress plugin. What I'm trying to inject is an image hyperlink.

3 个答案:

答案 0 :(得分:1)

您可以通过在主题functions.php或插件代码中添加以下内容来实现此目的:

add_action( 'wp_footer', 'add_new_element' );

function add_new_element() {
    echo '<a href="google.com"><img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"></a>';
}

它会在结束body代码

之前插入链接

答案 1 :(得分:1)

使用此功能。 See more in WordPress codex

<?php
function your_function() {
    echo '<p>This is inserted at the bottom</p>';
}
add_action( 'wp_footer', 'your_function' );
?>

答案 2 :(得分:0)

function your_function()
{
    echo '<p>This is inserted at the bottom</p>';
}

add_action('wp_footer', 'your_function');

代码进入活动子主题(或主题)的function.php文件。或者也可以在任何插件php文件中。

参考:wp_footer

希望这有帮助!