首页 文章

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

提问于
浏览
2

我已将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更改输出 . 在 Headers 和正文结束之前添加样式和脚本 .

2 回答

  • 0

    我想你想要WordPress与Magento集成然后你需要使用fishpig扩展名按照这个URL https://fishpig.co.uk/magento/wordpress-integration/

  • 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' );
    

相关问题