How Do I Add Additional CSS Class in WordPress?

Adding Additional CSS Classes in WordPress

There are a few ways to add additional CSS classes to your WordPress site. Firstly, you can use the add_class() function to add a class to an element on your page.

Secondly, you can use the wp_css() function to add a style to a specific WordPress theme or plugin. And finally, you can use the WordPress customizer to add new CSS classes to any element on your site.

Adding a Class with the add_class() Function

The add_class() function is located in the WordPress core functions file. To add a class to an element on your page, you will need to include the add_class() function, the name of the class you wish to add, and the name of the element on your page you wish to add the class to.

For example, if you want to add a class to the body element on your page, you would include the following code:

add_class( ‘my-class’ , ‘my-element’ );

Adding a Style with the wp_css() Function

The wp_css() function is located in the WordPress core functions file and allows you to add style to any WordPress theme or plugin. To use the wp_css() function, you will first need to include the wp_includes() function.

Then, you will include the wp_css() function, the path to the style file you wish to use, the name of the style you wish to add, and the name of the element on your page you wish to add the style to.

For example, if you want to add a style to the stylesheet located in the themes/my-theme/css folder of your WordPress site, you would include the following code:

wp_css( ‘styles.css’ , ‘my-element’ );

Adding a New CSS Class with the WordPress Customizer

The WordPress customizer is a WordPress admin panel that allows you to add, delete, and modify any WordPress theme or plugin. To add a new CSS class to an element on your site, you will first need to open the WordPress customizer and select the theme or plugin you wish to modify.

Then, you will open the CSS section of the customizer and add the new CSS class you wish to add to the class list. Finally, you will select the my-element element on your page and click the Save Changes button.