【发布时间】:2013-11-07 20:52:42
【问题描述】:
我遇到了一个有趣的挑战,但我还没有完成(我不是 WordPress 插件开发人员)。我正在使用一个以 OptimizePress 作为主题的网站。 Optimizepress 在构建页面时多次调用the_content。
我想在每个页面的正文中包含一个小代码 sn-p。
if ( function_exists( "transposh_widget" ) ) {
transposh_widget(array(), array(
'title' => 'Translation',
'widget_file' => 'flags/tpw_flags_css.php',
) );
}
这会显示几个标志,并允许您在网站上切换语言。所以我需要一个 div 设置为固定位置 / 0,0(我可以稍后调整外观),其中包含它。
除了在the_content 中输出某些内容(这似乎是执行此操作的流行方式)之外,在 wordpress 网站的每个页面上实现此目标的最佳方式是什么?
更新
下面的代码开始了 - 这是我的最终代码,它只在每个页面的网站右上角输出标志。
<?php
/*
Plugin Name: Transposh Flags in Header
Description: Embed Transposh Header Code (in Footer of Page)
*/
function insert_my_footer() {
echo '<div style="display:block; top:30px; right: 50px; position: fixed; color:white;">';
if (function_exists("transposh_widget")) {
transposh_widget(array(),
array('title'=>'',
'widget_file' => 'flags/tpw_flags.php') );
}
echo '</div>';
}
add_action('wp_footer', 'insert_my_footer');
?>
【问题讨论】:
-
你试过header.php吗?
-
或者footer.php,也许?
-
主题非常难用,我不想添加任何每次主题升级都会破坏的东西。试图将其插入主题之外。