Add class to the items in wp_list_pages

As wp_list_pages() has an argument of walker, you can use that to replace what is being used by walk_page_tree() as walker class internally. @Brady has left a nice example in this answer. class WPSE113482PageWalker extends Walker_Page { function start_el( &$output, $page, $depth, $args, $current_page ) { // Build $output here and apply your class for … Read more

adding a custom css class to post

Note – I recommend using the hook suggested by @Chip Bennett in another answer Here’s the modified version of that filter – function wpse_filter_post_class( $classes ) { $my_post_class = get_post_meta($post->ID, “your_meta_name”); if( $my_post_class != ” ) $classes[] = $my_post_class; return $classes; } add_filter( ‘post_class’, ‘wpse_filter_post_class’ ); You can setup a Custom fileds for that – … Read more

Remove and add class with body_class() function

The my_custom_class() function is using the class name my-custom-class, but the CSS is targeting the class my_custom_class. These two strings should be exactly the same: .my-custom-class { margin-top: 350px !important; } Also, it would be a little cleaner to handle all of the body_class stuff in a single callback function: add_action( ‘body_class’, ‘my_custom_class’); function my_custom_class( … Read more

Get parent category class in post_class()

Perhaps something like: function mytheme_get_post_class_parent_cats() { $parent_cat_classes = array(); // Get parent categories $post_cats = wp_get_post_categories(); // Loop through post categories foreach ( $post_cats as $post_cat ) { $cat_parents = get_category_parents( $post_cat , false, ‘,’, true ); // if there are any parent categories if ( $cat_parents ) { // create an array $cat_array = … Read more

How do I add a custom body class for a specific page ID?

The ID can/should be given without quotes (otherwise if you a page with ‘38034’ as slug/post_name, this will be used instead of the page with the ID 38034). And you want to return $classes no matter if you added your own or not. add_filter(‘body_class’, ‘custom_body_class’); function custom_body_class($classes) { if (is_page(38034)) $classes[] = ‘new-class’; return $classes; … Read more

Category as Class for Custom Post Type

This is expected (or at least: designed) behavior. Here is a portion of the Codex on that: The post_class CSS classes appear based upon the post pageview Conditional Tags as follows. Category Category template files and pageviews displaying posts feature the class selectors: post post-id category-ID category-name Of course, you can hook a custom filter … Read more

How to add classes to post_class?

The post_class function does also accept an array of classes. You can pass them to the function as follows: $classes = [ ‘card’, ‘grid-item’, ‘wow’, ‘fadeInUp’, $termsString ]; <div <?php post_class ( $classes ); ?>> … </div> You can store the custom field’s value inside a variable, and then pass it to the function just … Read more

Child Pages Loop

I’m fairly certain the problem is that some template tags rely on the global $post variable. Using setup_postdata() as you are now, will not alter $post. If you replace all the instances of $pageChild with $post, everything should work. However, I would strongly recommend using the WP_Query class and setting up your post data with … Read more