Support » Developing with WordPress » How can I Insert body codes into individual pages body tags with a plugin?

  • I need to insert <body class=”nolinks”> into many of my pages, but not all of them. I do not want to do this by editing my themes styles and messing with things that will either break or disable upon a theme update, and I do not want to use a child theme.

    So I’m wondering if anyone knows of a plugin that will allow me to insert this code into individual pages?

    Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi Semperaye,

    As per my knowledge there is no such plugin.

    Default wordpress has body class that is attached to the class attribute of body tag.
    you can use below filter to add class to the body tag.

    add_filter( 'body_class', 'custom_class' );
    function custom_class( $classes ) {
        if ( is_page_template( 'page-example.php' ) ) {//you can use page id by getting from get_the_id()    
            $classes = array(); //empty array or you can reuse this
            $classes[] = 'nolinks';
        return $classes;

    You can create your own plugin by adding this code in a file having plugin default code.
    i.e. creating you custom plugin code 🙂

    • This reply was modified 4 years, 12 months ago by iqbal1486.

    Hi Semperaye,

    You can use below plugin. It will give option to add class in page editor.

    Thread Starter semperaye


    Ty for the responses! I will try the plugin first. Then if that fails I’ll try to make my own… I’ll be sure to follow up ty!

    Thread Starter semperaye


    So the wp-custom-body-class plugin did not work.

    @iqbal1486 I do have a custom site plugin. I think that code you gave me is to put a class into all templates like full-width or default. I just need to add <body class=”nolinks”> to certain urls / pages. Any idea what that might look like?

    Thank you!

    The code i have provided is to add the class to specific template.
    You can use is_page function or any other functions of wp through which you get the id of that particular page. Use that condition instead of the is_page_tempalte and you are done.

    Please go through the code throughly


Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How can I Insert body codes into individual pages body tags with a plugin?’ is closed to new replies.