WordPress的注入代码到页眉和页脚在Magento WordPress的整合
我已经包括wordpress进入magento为了使用WordPress的功能,通过添加以下行到magentos index.php
。WordPress的注入代码到页眉和页脚在Magento WordPress的整合
define('WP_USE_THEMES', false);
require_once MAGENTO_ROOT . '/blog/wp-load.php';
但这种莫名其妙的代码注入WordPress的wp_head
和头wp_footer
代码和Magento的文件页脚。
这是我的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注入HTML到页眉和页脚,而不调用任何PHP函数(注风格和脚本标记)。我甚至也禁用了JS。任何帮助高度赞赏。
编辑: 这不是特有的magento。我将wp-load.php
包含到独立的php脚本和wordpress更改输出中。在标题和正文结束之前添加样式和脚本。
@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');
我想你想与Magento的WordPress的集成,那么你需要使用fishpig扩展按照这个网址 https://fishpig.co.uk/magento/wordpress-integration/
让我们忘记集成。我的问题是wordpress如何将代码注入到只包含html的php文件中。 – mysterious
到目前为止,我认为是wp在最终输出中搜索body和head标签,然后在发送到浏览器之前添加它的代码。 – mysterious
谢谢你..作品,但如果我钩入WP行动不起作用。如果我使用它没有任何行动,那么它的作品。试图找出一个适当的钩子。你也有一个想法,我应该在哪里包含这段代码?怎么样magento的index.php? – mysterious
@mysterious尝试'init'钩子。这是一个WordPress的安装,所以,正如我上面提到的functions.php文件将罚款(儿童主题或不)。如果它没有挂钩,就不要使用它。很高兴我能帮上忙。 – vagelis
我会尝试初始化。我没有把它放在functions.php中,因为我将WP_USE_THEMES设置为false。感谢您让我走上正轨。赏金颁发。 – mysterious