【问题标题】:wp_footer hook puts content below footerwp_footer 钩子将内容放在页脚下方
【发布时间】:2015-11-16 14:29:57
【问题描述】:

我在页脚上方放置一个红色注册栏的自定义插件是使用 wp_footer 将它放在页脚底部。如果我在过滤器中使用 the_content,那么它会将其放入 Woo Commerce 产品页面的描述中。有谁知道将这个动作从插件内部页脚的底部移动到顶部的方法?我已经尝试了很多东西的组合,但我却一无所获。感谢您的帮助。

注册栏插件

<?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); 

注册栏 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 ******************/

主题页脚.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>

谢谢

【问题讨论】:

    标签: wordpress


    【解决方案1】:

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

    【讨论】:

    • 我尝试用 get_footer 代替 wp_footer,但该栏根本没有显示。我会再试一次。必须有一种方法可以通过使用 the_content 过滤器在页脚上方放置一个红色条而不影响 woo 商务。对于解决方案的任何帮助将不胜感激。
    • 我会说检查你的主题以确保它实际上使用get_footer()
    • 之所以这样做,是因为这是 archive.php 的最后一行,在其他行中:
    • 我将页脚的 php 放在一个单独的文件中,然后将其放在插件文件中: get_footer('signup_bar/includes/signup-bar-footer.php');由于错误,它不会激活。我认为它与主题对 get_footer 的使用相冲突。必须有一种方法可以在不使用过滤器 the_content 的情况下在页脚上方放置一个栏。有什么想法吗?
    • 抱歉,我需要修改您的特定主题。我没用woocommerce,是直接用woocommerce,还是子主题?
    猜你喜欢
    • 2017-07-07
    • 1970-01-01
    • 2013-04-09
    • 2014-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-19
    相关资源
    最近更新 更多