Reece
Reece

Reputation: 2701

how to add a class to post_class();

How can I add the bootstrap class md-col-9 to this element when the classes are being pulled through by php?

<li <?php post_class(); ?>>
</li>

Upvotes: 0

Views: 912

Answers (2)

DanijelSVK
DanijelSVK

Reputation: 371

You can use optional parameter, which can be added to the post_class().

If you need to add only 1 class, then you can make like this <?php post_class( 'class-name' ); ?>

If you need to add more then 1 class, then your code may look like this

<?php

$classes = array(
    'class1',
    'class2',
    'class3',
);
?>

<div <?php post_class( $classes ); ?>>

You can read more about it at official documentation here https://codex.wordpress.org/Function_Reference/post_class

Upvotes: 1

Reece
Reece

Reputation: 2701

I figured it out it's actually very simple. I added my class like this:

<li <?php post_class('col-md-9'); ?>>
</li>

Upvotes: 0

Related Questions