[Support request] Custom stylesheet, where to place it?

Home Forums Support [Support request] Custom stylesheet, where to place it?

Home Forums Support Custom stylesheet, where to place it?

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #615654
    Jeffrey

    I had a custom stylesheet I load to style my login screen. I created a directory called “custom” under …/wp-content/themes/generatepress/

    and that is where the stylesheet was loaded from. However on the last update of theme, that directory got wiped and I had to restore the “custom” directory and .css file from backup.

    So what I am asking is there a safe place to put the stylesheet so it won’t get wiped out with theme updated. I know something about child themes but did not want to go that route necessarily, I just like having the stylesheet that just serves this one dedicated purpose. I believe I could just use an absolute path under /wp-content, just not sure about best practices or if it matters.

    So as it is the function looks like:

    function custom_login_stylesheet() {
    wp_enqueue_style( ‘custom-login’, get_stylesheet_directory_uri() . ‘/custom/adx_custom_login.css’ );
    }
    add_action( ‘login_enqueue_scripts’, ‘custom_login_stylesheet’ );

    GeneratePress 2.1.3
    GP Premium 1.6.2
    #615734
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    This is actually exactly what child themes are made for. It would prevent you from losing the changes when you update the parent theme.

    Alternatively, you could build a custom plugin using a plugin like this: https://wordpress.org/plugins/pluginception/

    You would need to replace get_stylesheet_directory_uri() with plugin_dir_url( __FILE__ ).

    #616216
    Jeffrey

    Ok thanks Tom. Yeah regarding the child theme, I kind of get that aspect, but at the same time, this stylesheet really has nothing to do with the theme. I guess I was just wondering if there was a best practice for locating or placing some custom stylesheets on a WP installation, looking for a safe spot where they would be secure and not get overwritten on updates. You are suggesting in the plugins area and just make a plugin for it, I’ll look into it, but trying to avoid plugin proliferation. But I could move the stylesheet there (plugins directory) and avoid an actual plugin, right? Seems like a simple enough task but trying to avoid tripping up over something.

    #616330
    Tom
    Lead Developer
    Lead Developer

    I suppose you could do that, but you would still need to add the function to enqueue the file. I suppose you could use a plugin like Code Snippets, but you’re still using a plugin then.

    Code is code, whether it’s a plugin, in a child theme or in the parent theme. There’s no difference performance-wise between any of those methods.

    #616463
    Jeffrey

    I am already using snippets for a number of things.

    #616837
    Tom
    Lead Developer
    Lead Developer

    In that case you can upload the file anywhere on your server outside of a theme or plugin that receives updates.

    Then use Code Snippets to enqueue the file.

    function custom_login_stylesheet() {
        wp_enqueue_style( 'custom-login', 'URL TO FILE HERE' );
    }
    add_action( 'login_enqueue_scripts', 'custom_login_stylesheet' );
    #617204
    Jeffrey

    Gotcha, thanks!

    #617410
    Tom
    Lead Developer
    Lead Developer
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.