Home » WordPress: How to Add CSS to a Specific Page URL

WordPress: How to Add CSS to a Specific Page URL

by Tutor Aspire

This is an interesting topic. A WordPress/WooCommerce client could not add CSS via the usual way. In fact, Gravity Forms plugin (and in particular the “directory” extension), stores entries in the database BUT the directory page and the entries filtered list have the same classes, ids, and cannot be “targeted” with CSS.

Long story short, and Gravity Form or not Gravity Form, here’s the snippet you can use to add CSS to any WordPress page as long as you know its URL.

PHP Snippet: Apply CSS to a Page URL That Contains “string”

/**
 * @snippet       Apply CSS if URL contains string - WordPress
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 3.5.7
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'init', 'tutoraspire_apply_css_if_url_contains_string' );
 
function tutoraspire_apply_css_if_url_contains_string() {
 
$url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
 
if ( false !== strpos( $url, 'string' ) ) {
    echo '';
} 
 
}

You may also like