【问题标题】:Wordpress injects code to header and footer in Magento Wordpress IntegrationWordpress 在 Magento Wordpress 集成中将代码注入页眉和页脚
【发布时间】:2017-08-05 00:59:54
【问题描述】:

我已将 wordpress 包含在 magento 中,以便通过向 magentos index.php 添加以下行来使用 wordpress 功能。

define('WP_USE_THEMES', false);
require_once MAGENTO_ROOT . '/blog/wp-load.php';

但是这段代码以某种方式在 magento 文件的页眉和页脚中注入了 wordpress wp_headwp_footer 代码。

这是我的 magento 模板文件 (2columns-left.phtml)。

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>

</body>
</html>

但输出是

<!DOCTYPE html>
<html lang="en">
<head>
<style type="text/css">
img.wp-smiley,
img.emoji {
    display: inline !important;
    border: none !important;
    box-shadow: none !important;
    height: 1em !important;
    width: 1em !important;
    margin: 0 .07em !important;
    vertical-align: -0.1em !important;
    background: none !important;
    padding: 0 !important;
}
</style>
    <style type="text/css">
        .mobile-menu {
            position: -webkit-sticky;
            position: -moz-sticky;
            position: -ms-sticky;
            position: -o-sticky;
            position: sticky;
        }
    </style>
    </head>
<body>
<script type='text/javascript' src='https://SITNAME.com/blog/wp-includes/js/jquery/jquery.js?ver=1.12.4'></script>
<script type='text/javascript' src='https://SITNAME.com/blog/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1'></script>
</body>
</html>

无法理解 wp 如何在不调用任何 php 函数的情况下将 html 注入页眉和页脚(注意样式和脚本标签)。甚至我也禁用了 JS。任何帮助都非常感谢。

编辑: 这不是 magento 特有的。我将wp-load.php 包含在一个独立的 php 脚本中,然后 wordpress 更改输出。在标题和正文结束之前添加样式和脚本。

【问题讨论】:

    标签: php wordpress magento magento-1.9


    【解决方案1】:

    @mysterious 你能在你的functions.php 中试试这个然后回复我们吗?

    function unhook_wp_head_footer(){
      global $wp_filter,$wpdb,$wp_query;
    
      if(is_page('2columns-left.phtml')) {
        foreach ( $wp_filter['wp_head'] as $priority => $wp_head_hooks ) {
          if( is_array( $wp_head_hooks ) ) {
            foreach ( $wp_head_hooks as $wp_head_hook ) {
              remove_action( 'wp_head', $wp_head_hook['function'], $priority );
            }
          }
        }
    
        foreach ($wp_filter['wp_footer'] as $priority => $wp_footer_hooks ) {
          if( is_array( $wp_footer_hooks ) ){
            foreach ( $wp_footer_hooks as $wp_footer_hook ) {
              remove_action( 'wp_footer', $wp_footer_hook['function'], $priority );
            }
          }
        }
      }
    }
    
    add_action( 'wp', 'unhook_wp_head_footer' );
    

    【讨论】:

    • 谢谢伙计.. 工作但如果我挂钩 wp 操作则不起作用。如果我在没有任何操作的情况下使用它,那么它就可以工作。现在试图找出一个合适的钩子。你也知道我应该在哪里包含这个代码? magento 的 index.php 怎么样?
    • @mysterious 尝试 'init' 钩子。这是一个 wordpress 安装,所以正如我上面提到的 functions.php 文件会很好(子主题与否)。如果它在没有钩子的情况下工作,那就不要使用一个。很高兴我能帮上忙。
    • 我会尝试初始化。我没有把它放在functions.php 中,因为我将WP_USE_THEMES 设置为false。谢谢你让我走上正轨。赏金。
    【解决方案2】:

    我认为您希望 WordPress 与 Magento 集成,然后您需要使用 fishpig 扩展,请按照此 URL https://fishpig.co.uk/magento/wordpress-integration/

    【讨论】:

    • 让我们忘记集成。我的问题是 wordpress 如何将代码注入仅包含 html 的 php 文件中。
    • 到目前为止,我认为 wp 在最终输出中搜索 body 和 head 标签,然后在发送到浏览器之前添加其代码。
    猜你喜欢
    • 1970-01-01
    • 2016-08-29
    • 1970-01-01
    • 2021-03-22
    • 1970-01-01
    • 2013-07-05
    • 2020-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多