wp_footer 钩子将内容放在页脚下方 [英] wp_footer hook puts content below footer

查看:24
本文介绍了wp_footer 钩子将内容放在页脚下方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的自定义插件将红色注册栏放在页脚正上方,使用 wp_footer 将其放在页脚底部.如果我在过滤器中使用 the_content,那么它会将其放入 Woo Commerce 产品页面的描述中.有谁知道如何将此操作从插件内部页脚的底部移动到顶部?我尝试了很多东西的组合,但无处可去.感谢您的帮助.

注册栏插件

<!--/** 使用它来结束 PHP 的动作钩子测试.为 php 变量添加下一行.*/--><注册><form class="flex-container" accept-charset="UTF-8" method="POST" action="https://eu943.infusionsoft.com/app/form/process/ae41b9e4b0750e3e3aa3ae78337d5fa6"><input name="inf_form_xid" type="hidden" value="ae41b9e4b0750e3e3aa3ae78337d5fa6"><input name="inf_form_name" type="hidden" value="CCG Newsletter Sign Up"><input name="infusionsoft_version" type="hidden" value="1.38.0.37"><div class="flex-container"><h3 class="signup-message">获取开始、资助和发展您的伟大企业的技巧:</h3>

<div class="flex-container"><input id="inf_field_FirstName" name="inf_field_FirstName" type="text" placeholder="名字*">

<div class="flex-container"><input style="margin:10px 0;"id="inf_field_Email" name="inf_field_Email" type="text" placeholder="Email*">

<div class="flex-container"><input class="input.flex-container ccg-button" type="submit" value="START NOW">

</表单></注册><?php}//省略关闭 PHP 标记以避免标题已发送"问题.//下面的额外代码显示过去的试验,目前已注释掉/* 与基于 HTML 的函数一起使用时,接下来的两行代码将仅将栏放在 Woo 页面上的正确位置 *//*remove_action('woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 1);add_action('woocommerce_after_main_content', 'signup_bar', 1);*//* 这行代码将使注册栏在普通页面上正确,但在woo页面上的描述中.仅当函数代码完全在 php 内部时才有效 *//*add_filter('the_content', 'signup_bar',1);*//*下面的代码在所有页面上都能正常工作,但在页脚底部,而不是顶部.*/add_action('wp_footer', 'signup_bar', 1);

注册栏 CSS

#main.clearfix.width-100{padding-right:0px!important;padding-left:0px!important;}/* 整体容器 */报名  {保证金:自动;填充:自动 0px!重要;字体大小:80%;背景:#d03925;文本对齐:居中;显示:弹性;/* 新,规范 - Opera 12.1,Firefox 20+ */显示:-webkit-flex;/* 新 - 铬 */显示:-moz-box;/* 旧 - Firefox 19-(有问题,但大多数情况下有效)*/-webkit-align-items:居中;对齐项目:居中;-webkit-justify-content:中心;对齐内容:居中;}/* 开始 Flex */.flex 容器 {文本对齐:居中;显示:弹性;/* 新,规范 - Opera 12.1,Firefox 20+ */显示:-webkit-flex;/* 新 - 铬 */显示:-moz-box;/* 旧 - Firefox 19-(有问题,但大多数情况下有效)*/-webkit-align-items:居中;对齐项目:居中;-webkit-justify-content:中心;对齐内容:居中;}/* 移动优先 */.flex 容器{弹性方向:列;-webkit-box-flex-direction: 列;-moz-box-flex-direction: 列;-webkit-flex-direction: 列;边距:0 0 5px 0;填充:15px;}/* 桌面 - 转到大于 1000 像素的屏幕的行 */@media 屏幕和(最小宽度:1024px){.flex 容器{弹性方向:行;-webkit-box-flex-direction: 行;-moz-box-flex-direction:行;-webkit-flex-direction: 行;边距:0 10px;填充:10px 0;}}/* 结束弹性 */h3.signup-message, .signup-message{保证金:自动;填充:0;颜色:#ffffff !重要;字体系列:'lato',无衬线;字体粗细:500;文本对齐:居中;字体大小:20px;行高:30px;}#inf_field_FirstName, #inf_field_Email {边框:1px 实心 #d2d2d2;字体大小:15px;字体系列:'lato',无衬线;颜色:#747474;填充:15px 5px;宽度:270px;}.ccg 按钮 {边框宽度:2px;边框样式:实心;边框颜色:#ffffff;背景:#d03925;颜色:#fff;字体系列:'lato',无衬线;字体粗细:700;行高:20px;字体大小:15px;光标:指针;填充:13px 30px 13px 30px;}.ccg-button:hover, .ccg-button:focus, .ccg-button:active{边框宽度:2px;边框样式:实心;边框颜色:#d03925;颜色:#d03925;背景:#ffffff;}/************** 结束注册栏********************/

主题页脚.PHP

<!-- fusion-row -->

<!-- #main --><?php全球 $social_icons;如果 (strpos(Avada()->settings->get('footer_special_effects'), 'footer_sticky') !== FALSE) {回声'</div>';}//获取正确的页面ID$c_pageID = Avada::c_pageID();//只包含页脚如果(!is_page_template('blank.php')){$footer_parallax_class = '';if ( Avada()->settings->get( 'footer_special_effects' ) == 'footer_parallax_effect' ) {$footer_parallax_class = 'fusion-footer-parallax';}echo sprintf('<div class="fusion-footer%s">', $footer_parallax_class );//检查页脚小部件区域是否应该显示if ( ( Avada()->settings->get('footer_widgets' ) && get_post_meta( $c_pageID, 'pyre_display_footer', true ) != 'no' ) ||(!Avada()->settings->get('footer_widgets') && get_post_meta( $c_pageID, 'pyre_display_footer', true ) == 'yes' )){?><footer class="fusion-footer-widget-area"><div class="fusion-row"><div class="fusion-columns fusion-columns-<?php echo Avada()->settings->get('footer_widgets_columns'); ?> fusion-widget-area"><?php//根据主题选项中选择的列数检查列宽$column_width = 12/Avada()->settings->get('footer_widgets_columns');if( Avada()->settings->get('footer_widgets_columns' ) == '5' ) {$column_width = 2;}//渲染与主题选项中选择的一样多的小部件列for ( $i = 1; $i <7; $i++ ) {if ( Avada()->settings->get('footer_widgets_columns') >= $i ) {echo sprintf('<div class="fusion-column col-lg-%s col-md-%s col-sm-%s">', $column_width, $column_width, $column_width );if ( function_exists( 'dynamic_sidebar' ) &&dynamic_sidebar('avada-footer-widget-'.$i)){//一切都好,dynamic_sidebar() 已经调用了渲染}回声'</div>';}}?><div class="fusion-clearfix"></div>

<!-- 融合列-->

<!-- fusion-row --></页脚><!-- fusion-footer-area --><?php}//结束页脚检查//检查页脚版权区域是否应该显示if ( ( Avada()->settings->get('footer_copyright' ) && get_post_meta( $c_pageID, 'pyre_display_copyright', true ) != 'no' ) ||(!Avada()->settings->get('footer_copyright') && get_post_meta( $c_pageID, 'pyre_display_copyright', true ) == 'yes' )){?><footer id="footer" class="fusion-footer-copyright-area"><div class="fusion-row"><div class="fusion-copyright-content"><?php/*** avada_footer_copyright_content 钩子** @hooked avada_render_footer_copyright_notice - 10(输出主题选项页脚版权文本的 HTML)* @hooked avada_render_footer_social_icons - 15(输出页脚社交图标的 HTML)*/do_action('avada_footer_copyright_content');?>

<!-- fusion-fusion-copyright-area-content -->

<!-- fusion-row --></页脚><!-- #footer -->

<!-- fusion-footer --><?php}//结束页脚版权区域检查}//结束是不是空白页检查?>

<!-- 包装器 --><?php//检查是否使用盒装侧标题布局;如果是这样,请关闭 #boxed-wrapper 容器if ( ( ( ( Avada()->settings->get( 'layout' ) == 'Boxed' && get_post_meta( $c_pageID, 'pyre_page_bg_layout', true ) == 'default' ) || get_post_meta($c_pageID, 'pyre_page_bg_layout', true ) == 'boxed' ) &&Avada()->settings->get('header_position') != 'Top'){?>

<!-- #boxed-wrapper --><?php}?><!-- W3TC-include-js-head --><?phpwp_footer();//回显添加到before </body>"的脚本主题选项中的字段echo Avada()->settings->get('space_body');?><!--[如果是 IE 8]><script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/assets/js/respond.js"></script><![endif]--></html>

谢谢

解决方案

wp_footer() 将在 </body> 之前被调用,而不是函数获取主题页脚.您正在寻找 get_footer() 但是,许多主题实际上并没有使用 get_footer(),因此如果您正在寻找大量分发,那将不是一个非常可靠的方法.也就是说,有些主题也不使用 wp_footer().

My custom plugin to put a red sign-up bar just above the footer is putting it at the bottom of the footer using wp_footer. If I use the the_content in a filter, then it puts it into the description of the Woo Commerce product pages. Does anyone know of a way to move this action from the bottom to the top of the footer inside of the plugin? I have tried many combinations of things and am just getting no where. Thank you for helping.

Signup Bar Plugin

<?php 
/*
Plugin Name: ccg-signup
Description:  Adds an eye-catching signup bar to the bottom of the page
Author: Teresa Light
Author URI: https://teresalight.com
Plugin URI: 
Version: 1.0
License: 
*/

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

/**
 * Register style sheet.
 */

   add_action( 'wp_enqueue_scripts', 'register_plugin_styles' );


  function register_plugin_styles() {
    wp_register_style( 'ccg-signup', plugins_url( 'ccg-signup/css/signup-bar.css' ) );
    wp_enqueue_style( 'ccg-signup' );
    }

/**
 * Add HTML markup for the bar
 */

    function signup_bar($content){
    ?>  <!-- /** Use this to end PHP for the action hook test.  Add the next line for the php variable instead.*/ -->

            <signup>
                    <form class="flex-container" accept-charset="UTF-8" method="POST" action="https://eu943.infusionsoft.com/app/form/process/ae41b9e4b0750e3e3aa3ae78337d5fa6">
                        <input name="inf_form_xid" type="hidden" value="ae41b9e4b0750e3e3aa3ae78337d5fa6">
                        <input name="inf_form_name" type="hidden" value="CCG Newsletter Sign Up">
                        <input name="infusionsoft_version" type="hidden" value="1.38.0.37">

                        <div class="flex-container">
                            <h3 class="signup-message">Get tips to start, fund and grow Your Great Business:</h3>
                        </div> 

                        <div class="flex-container">
                            <input id="inf_field_FirstName"  name="inf_field_FirstName" type="text" placeholder="First Name*">
                        </div>

                        <div class="flex-container">
                            <input style="margin:10px 0;"id="inf_field_Email" name="inf_field_Email" type="text" placeholder="Email*">
                        </div>

                        <div class="flex-container">
                            <input class="input.flex-container ccg-button" type="submit" value="START NOW">
                        </div>
                    </form>
            </signup>
    <?php
    }
// Omit closing PHP tag to avoid "Headers already sent" issues.
// EXTRA CODE BELOW SHOWING PAST TRIALS, CURRENTLY COMMENTED OUT
/* The next two lines of code when used with the HTML based function will put the bar in the right place on Woo pages only */
/*remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 1);
add_action('woocommerce_after_main_content', 'signup_bar', 1);
 */

/* This line of code will put the signup bar correct on normal pages but in the description on the woo pages. It only works when the function code is totally inside of php */
/*add_filter( 'the_content', 'signup_bar',1 );*/


/*The code below works correctly on all pages but at the bottom of the footer, and not the top.*/
add_action( 'wp_footer', 'signup_bar', 1); 

Signup Bar CSS

#main.clearfix.width-100{
    padding-right:0px!important;
    padding-left:0px!important;
}

/* Overall Container */
signup  {
  margin: auto;
  padding: auto 0px!important;
  font-size:80%;
  background: #d03925;
  text-align: center;  
  display: flex;  /* NEW, Spec - Opera 12.1, Firefox 20+ */
  display: -webkit-flex; /* NEW - Chrome */
  display: -moz-box;         /* OLD - Firefox 19- (buggy but mostly works) */
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
}
/* Begin Flex */
.flex-container {
  text-align: center;  
  display: flex;  /* NEW, Spec - Opera 12.1, Firefox 20+ */
  display: -webkit-flex; /* NEW - Chrome */
  display: -moz-box;         /* OLD - Firefox 19- (buggy but mostly works) */
   -webkit-align-items: center;
   align-items: center;
   -webkit-justify-content: center;
   justify-content: center;
}

/* MOBIL FIRST */
.flex-container{
   flex-direction: column;
   -webkit-box-flex-direction: column;
  -moz-box-flex-direction: column;
  -webkit-flex-direction: column;
  margin:0 0 5px 0;
  padding:15px;
}

/* DESKTOPS - go to a row for screens greater than 1000px */ 
@media screen and (min-width: 1024px) {
  .flex-container{
   flex-direction: row;
   -webkit-box-flex-direction: row;
  -moz-box-flex-direction: row;
  -webkit-flex-direction: row;
  margin:0 10px;
  padding:10px 0;
  }
}
/* End  Flex */

h3.signup-message, .signup-message{
  margin: auto;
  padding:0;
  color: #ffffff !important;
  font-family: 'lato', sans-serif;
  font-weight: 500; 
  text-align:center;
  font-size:20px;
  line-height:30px;
}

#inf_field_FirstName, #inf_field_Email {
  border: 1px solid #d2d2d2;
  font-size: 15px;
  font-family: 'lato', sans-serif;
  color: #747474;
  padding: 15px 5px;
  width: 270px;
}

.ccg-button {
    border-width: 2px;
    border-style: solid;
    border-color:#ffffff;
    background: #d03925;
    color: #fff;
    font-family: 'lato', sans-serif;
    font-weight: 700;
    line-height: 20px;
    font-size:15px;
    cursor: pointer;
    padding: 13px 30px 13px 30px;
}
.ccg-button:hover, .ccg-button:focus, .ccg-button:active{
    border-width:2px;
    border-style: solid;
    border-color:#d03925;
    color:#d03925;
    background: #ffffff;
}
/************** END SIGNUP BAR ******************/

THEME FOOTER.PHP

                </div>  <!-- fusion-row -->
            </div>  <!-- #main -->

            <?php
            global $social_icons;

            if ( strpos( Avada()->settings->get( 'footer_special_effects' ), 'footer_sticky' ) !== FALSE ) {
                echo '</div>';
            }

            // Get the correct page ID
            $c_pageID = Avada::c_pageID();

            // Only include the footer
            if ( ! is_page_template( 'blank.php' ) ) {

                $footer_parallax_class = '';
                if ( Avada()->settings->get( 'footer_special_effects' ) == 'footer_parallax_effect' ) {
                    $footer_parallax_class = ' fusion-footer-parallax';
                }

                echo sprintf( '<div class="fusion-footer%s">', $footer_parallax_class );

                    // Check if the footer widget area should be displayed
                    if ( ( Avada()->settings->get( 'footer_widgets' ) && get_post_meta( $c_pageID, 'pyre_display_footer', true ) != 'no' ) ||
                         ( ! Avada()->settings->get( 'footer_widgets' ) && get_post_meta( $c_pageID, 'pyre_display_footer', true ) == 'yes' )
                    ) {
                    ?>
                        <footer class="fusion-footer-widget-area">
                            <div class="fusion-row">
                                <div class="fusion-columns fusion-columns-<?php echo Avada()->settings->get( 'footer_widgets_columns' ); ?> fusion-widget-area">

                                    <?php
                                    // Check the column width based on the amount of columns chosen in Theme Options
                                    $column_width = 12 / Avada()->settings->get( 'footer_widgets_columns' );
                                    if( Avada()->settings->get( 'footer_widgets_columns' ) == '5' ) {
                                        $column_width = 2;
                                    }

                                    // Render as many widget columns as have been chosen in Theme Options
                                    for ( $i = 1; $i < 7; $i++ ) {
                                        if ( Avada()->settings->get( 'footer_widgets_columns' ) >= $i ) {
                                            echo sprintf( '<div class="fusion-column col-lg-%s col-md-%s col-sm-%s">', $column_width, $column_width, $column_width );

                                                if ( function_exists( 'dynamic_sidebar' ) &&
                                                     dynamic_sidebar( 'avada-footer-widget-' . $i )
                                                ) {
                                                    // All is good, dynamic_sidebar() already called the rendering
                                                }
                                            echo '</div>';
                                        }
                                    }
                                    ?>

                                    <div class="fusion-clearfix"></div>
                                </div> <!-- fusion-columns -->
                            </div> <!-- fusion-row -->
                        </footer> <!-- fusion-footer-area -->
                    <?php
                    } // end footer wigets check

                    // Check if the footer copyright area should be displayed
                    if ( ( Avada()->settings->get( 'footer_copyright' ) && get_post_meta( $c_pageID, 'pyre_display_copyright', true ) != 'no' ) ||
                          ( ! Avada()->settings->get( 'footer_copyright' ) && get_post_meta( $c_pageID, 'pyre_display_copyright', true ) == 'yes' )
                    ) {
                    ?>
                        <footer id="footer" class="fusion-footer-copyright-area">
                            <div class="fusion-row">
                                <div class="fusion-copyright-content">

                                    <?php
                                    /**
                                     * avada_footer_copyright_content hook
                                     *
                                     * @hooked avada_render_footer_copyright_notice - 10 (outputs the HTML for the Theme Options footer copyright text)
                                     * @hooked avada_render_footer_social_icons - 15 (outputs the HTML for the footer social icons)
                                     */
                                    do_action( 'avada_footer_copyright_content' );
                                    ?>

                                </div> <!-- fusion-fusion-copyright-area-content -->
                            </div> <!-- fusion-row -->
                        </footer> <!-- #footer -->
                    </div> <!-- fusion-footer -->
                <?php
                } // end footer copyright area check
            } // end is not blank page check
            ?>
        </div> <!-- wrapper -->

        <?php
        // Check if boxed side header layout is used; if so close the #boxed-wrapper container
        if ( ( ( Avada()->settings->get( 'layout' ) == 'Boxed' && get_post_meta( $c_pageID, 'pyre_page_bg_layout', true ) == 'default' ) || get_post_meta( $c_pageID, 'pyre_page_bg_layout', true ) == 'boxed' ) &&
             Avada()->settings->get( 'header_position' ) != 'Top'

        ) {
        ?>
            </div> <!-- #boxed-wrapper -->
        <?php
        }

        ?>

        <!-- W3TC-include-js-head -->

        <?php
        wp_footer();

        // Echo the scripts added to the "before </body>" field in Theme Options
        echo Avada()->settings->get( 'space_body' );
        ?>

        <!--[if lte IE 8]>
            <script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/assets/js/respond.js"></script>
        <![endif]-->
    </body>
</html>

THANK YOU

解决方案

wp_footer() is to be called right before </body> and is NOT the function for getting the themes footer. You are looking for get_footer() However, many themes do not actually use get_footer(), so if you are looking for mass distribution, that will not be a very reliable method. That said, some themes don't use wp_footer() either.

这篇关于wp_footer 钩子将内容放在页脚下方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆