• I want to move the style.css in the header to the footer. How should I change the theme code below?

    // Register the front-end stylesheet.
    wp_register_style(
    ‘quick-download-button-front-end-styles’, // label
    plugins_url( ‘css/style.css’, __FILE__ ), // CSS file
    array(), // dependencies
    filemtime( plugin_dir_path( __FILE__ ) . ‘css/style.css’ ) // set version as file last modified time
    );

    Note: The name of the installed plugin is Quick Download Button.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • > I want to move the style.css in the header to the footer

    Why would you want to do that?

    None of the code you provided is related to where the the css gets printed.
    Also, – if you edit this in any way it will just get over-written the next time the plugin gets updated.

    Input and the adjust whatever css you want to use through Customizer –> Additional CSS.

    The theme I use has a custom CSS box and in there I can keep a huge selection of CSS for my various needs.

    I have not looked over other themes much but in the Customizer it is at the bottom of the list of options

    You can deregister the plugin’s stylesheet and register it again later in the footer. Place this code in your functions.php or use the Code Snippets plugin.

    add_action('wp_enqueue_scripts', 'wpsf_deregister_qdbu_style', 20);
    function wpsf_deregister_qdbu_style()
    {
      wp_deregister_style('quick-download-button-front-end-styles');
    }
    
    add_action('wp_print_footer_scripts', 'wpsf_register_qdbu_style', 5);
    function wpsf_register_qdbu_style()
    {
      wp_register_style(
        'quick-download-button-front-end-styles',
        plugins_url() . '/quick-download-button/css/style.css',
        array(),
        filemtime(plugin_dir_path(WP_PLUGIN_DIR . '/quick-download-button') . 'quick-download-button/css/style.css')
      );
    };

    Here are some links with a bit more explanation.

    To dequeue a style, it has to have been registered before you try to remove it. The best way to achieve this is to set a higher priority for your event and then run it.

    https://developer.www.ads-software.com/reference/functions/wp_dequeue_style/#comment-3443

    You can use print_late_styles() function which is called in footer. You just need to enqueue your styles when header is already passed.

    So you need to find some hook which is called on each page and after wp_head hook. For example get_footer could be one.

    https://wordpress.stackexchange.com/a/186066

    I should note this is a brittle solution because it requires hardcoding of the plugin name. But Quick Download Button didn’t provide any action hooks or filters to do this more cleanly.

    WordPress makes use of the following constants when determining the path to the content and plugin directories. These should not be used directly by plugins or themes

    https://codex.www.ads-software.com/Determining_Plugin_and_Content_Directories

    Thread Starter Zeliha Canderengul

    (@zelihacanderengul)

    @rickymccallum87 the code did not run.

    @zelihacanderengul I’ll need some more information to help you troubleshoot further.

    If you made any changes to the Quick Download Button plugin code, you should revert them by deleting and reinstalling it. The code I provided should be placed in a separate plugin or child theme or dropped into the Code Snippets plugin.

    I noticed during a previous visit to your site that you had caching plugins active, which changed how stylesheets were loaded. I tested my code on a fresh install of WordPress 5.9 with the Twenty Twenty One theme. So I recommend using the Health Check plugin along with Code Snippets to see if you can get the result you wanted. If that’s successful, then enable plugins one by one to find out which is responsible for breaking the functionality.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘I want to move the style.css in the header to the footer’ is closed to new replies.