Wordpress 在 Magento Wordpress Integration 中向页眉和页脚注入代码
Wordpress injects code to header and footer in Magento Wordpress Integration
我已将 wordpress 包含到 magento 中,以便通过向 magento 添加以下行来使用 wordpress 功能 index.php
。
define('WP_USE_THEMES', false);
require_once MAGENTO_ROOT . '/blog/wp-load.php';
但是这段代码以某种方式在 magento 文件的页眉和页脚中注入了 wordpress wp_head
和 wp_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 更改了输出。在页眉和正文结束之前添加样式和脚本。
我想你想要 WordPress 与 Magento 集成然后你需要使用 fishpig 扩展遵循这个 URL
https://fishpig.co.uk/magento/wordpress-integration/
@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' );
我已将 wordpress 包含到 magento 中,以便通过向 magento 添加以下行来使用 wordpress 功能 index.php
。
define('WP_USE_THEMES', false);
require_once MAGENTO_ROOT . '/blog/wp-load.php';
但是这段代码以某种方式在 magento 文件的页眉和页脚中注入了 wordpress wp_head
和 wp_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 更改了输出。在页眉和正文结束之前添加样式和脚本。
我想你想要 WordPress 与 Magento 集成然后你需要使用 fishpig 扩展遵循这个 URL https://fishpig.co.uk/magento/wordpress-integration/
@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' );