How run shortcode before loading header.php in wordpress? [closed]

十年热恋 提交于 2020-01-07 07:44:13

问题


guys. I have some situation when my shortcode don't work correctly, if I add shortcode in header, because first of all load header.php and only after that load my shortcode. How can I run shortcode before loading header.php ? I try to use hoocks, but not find solution. Best regards.


回答1:


If you want to run your code just before your header.php is loaded you can use the get_header hook:

function run_before_header( $name ) {
    do_shortcode...
}
add_action( 'get_header', 'run_before_header' );



回答2:


You have a Widget in the Backend of your WP-Admin and the Widget is called: "my_specials" and you want to display this Widget in the header, right? OK; try doing something like this within the header.php:

    <?php
        // FILENME: header.php

        ob_start();
        dynamic_sidebar('my_specials');
        $mySpecials   = ob_get_clean();

        // NOW YOU HAVE THE CONTENT OF THE 'my_specials' WIDGET IN THAT VARIABLE.
        // ANY YOU CAN NOW ECHO IT AT THE SECTION OF YOUR CHOOSING LIKE SO:
        echo $mySpecials

It is imagined that this is what you meant and also hoped that this might help a bit, though...

Good-Luck to you, Mate...



来源:https://stackoverflow.com/questions/37612905/how-run-shortcode-before-loading-header-php-in-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!