• I see that there is a Custom CSS area in the theme, but wondered if there is any way to inject a link into the head of the page to an external CSS file. I’d like to be able to switch between a few different sets of custom CSS, rather than changing all the entries in the Custom CSS area every time.

    While the Custom CSS is placed inside the head, it is also inside a style block. So, I’m looking for a way to inject a link tag into the head, just after the Custom CSS style block, before the closing of the head.

    Thanks.

Viewing 1 replies (of 1 total)
  • AddWeb Solution

    (@addweb-solution-pvt-ltd)

    Hello kengr,

    Using Child Theme and Enqueqe Style
    Using the Child Theme is what we recommend if you want to make some mid-range to large-sized customizations because it’s the safest way to customize your website. With the Child Theme, you’ll be able to maintain your codes and update your core theme files easily.

    You can install our official Child Theme or you can create your own. You can then start to add your CSS codes and customize your website right away in Appearance > Editor. However, if you want to add external CSS files and Javascripts files, you have to call it and write some codes in functions.php.

    Here’s how it goes:
    Get your CSS or Javascript File ready or if it’s a remote source, get the link ready.
    Create a file named functions.php
    Add the following code in functions.php

    <?php
    
    function add_theme_codes() {
    
     wp_enqueue_style( ‘style’, get_stylesheet_directory_uri().’/myexternalcode.css’, ‘all’);
    
    }
    
    add_action( ‘wp_enqueue_scripts’, ‘add_theme_codes’ );
    
    ?>

    With this code, you’re creating a new action for your style sheet and calling it from the child-theme directory. Let’s say you have a “custom.css” file that needs to be added to your website.

    Hope this may help you,
    Thanks.

Viewing 1 replies (of 1 total)
  • The topic ‘Any way to link to an external style sheet for custom CSS?’ is closed to new replies.