Wordpress在Magento Wordpress Integration中向页眉和页脚注入代码

时间:2017-07-31 20:02:52

标签: php wordpress magento magento-1.9

我已将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>

不能理解如何在不调用任何php函数(注释样式和脚本标记)的情况下将wp注入页眉和页脚。即使我也禁用了JS。任何帮助高度赞赏。

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

2 个答案:

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

答案 1 :(得分:0)

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