The error you get is produced by $slug = get_post( $post )->post_name;
because there is no post_name
on a 404 page. So, to prevent this error you must structure the function in a way it doesn’t get to this line when it is called on a 404-page. Like this:
add_filter ('post_class', 'fl_pages_bodyclass');
add_filter ('body_class', 'fl_pages_bodyclass');
function fl_pages_bodyclass ($classes) {
global $post;
if (!is_404()) {
$slug = get_post($post)->post_name;
$classes[] = $slug;
}
return $classes;
}
Related Posts:
- How to filter posts that belong to a specific category only if that is the only category
- More then one menu items are assigned with “current-menu-item” class
- add to end of post in the loop with plugin
- Get current taxonomy and display query accordingly
- Keep post format class with isotope filter
- Print Current Post Index number within Loop
- rewind_posts() – what actually the use of it, and where using is required or preferred?
- How to show list of posts by author and category?
- How to publish a post with empty title and empty content?
- Override the default number of posts to show for a single loop?
- How to add a “publish” link to the quick actions
- WordPress Number of Posts Not Changing With posts_per_page
- Why is wordpress removing some unicode characters (e.g. some emojis) when I save my post?
- Find most recent authors
- Get the author of the latest revision
- Strange switch_to_blog() issue
- Multiple loops in same page, without duplicate content
- loop not displaying posts on custom template page
- How to Display Post View Count
- Displaying the number of posts in a custom loop (without including the number of posts of a loop below)?
- The correct way to call posts with ajax
- Converting multiple loops into one single loop with pagination
- How would I get 1 latest post from a query for 5 posts?
- Getting post id from wp_insert_post_data function?
- How can i do something after head like adding a hook for after head but before post
- Amend wordpress password function
- Alternating post layout
- Check to see if specific loop has less than certain amount of posts
- Adding specific post category between posts in loop
- Multiple loops are not reset
- Exclude category from
- Blog post per page setting conflicting with custom WP_Query?
- How to exclude latest x posts from a paginated query?
- Default to ‘all’ view on the ‘edit-post’ screen for authors
- Pausing and Resuming WP_Query results
- Post Loop Missing Most Recent Post
- How to : pagination in 3 different custom loops on the same page
- Sharing post from archive page (loop) doesn’t work
- Start WP Pagination From Number 1 in URL
- Use two different post_per_page limits with infinite scroll
- Wrong post title displayed from loop
- Change all author links in Blog roll
- Showing categories and subcategories with posts
- Get the amount of posts on a current page
- Is it possible to filter the main loop to exclude posts from a specific category?
- older blog posts not showing in new theme
- How to get posts published on the latest date?
- Page and post loop same template
- WordPress Query Posts From Category Post on Static Page
- Loop through posts? Want to remove extra newlines in actual post HTML/content on backend
- WP_Query: Show 10 posts in date order, first three random
- WordPress Loop: How to display recent posts in multiple divs
- Restrict displaying posts to the poster itself (in Back-end)
- Cannot implement byline into posts container in single.php
- Optimizing the blog loop
- How to check if there are posts with the same tag
- Exists filter or action that change Add New Post link?
- Accessing Post ID Within Loop
- Different number of posts per row in grid layout
- linking to post outside the loop
- WP_Query of Category Not Showing First Post
- How come this loop is not working? [closed]
- Using the loop to set locations for all posts on a single google map
- changing parent_id on post
- Defining ‘last’ class on foreach blog posts
- can’t modify post title using the_posts filter
- Want to change the post every three days with in specific category
- Separate top level categories on archive-product.php by meta
- While loop in functions.php outputting the_title() of each post on frontpage
- Shortcode for Comments and Comment Boxes in Post Loop
- Using AJAX to filter posts without refreshing page
- Permalink Short code showing unnecessary link text inside the loop
- Dropdown Select Post Filter
- How can I get the last post while on the first post for pagination? As if it were infinite
- show only one category and filter by tag
- Double loop output
- Prevent WordPress from putting around specific element
- filter buddypress users posts by user ‘xprofile’ custom fields
- post->ID displays the same ID number for every post
- Posts are not showing up on next page.
- Printable Page with all Posts from Tag
- Hide Admin posts & pages in Dashboard
- How to get the postID inside ‘content_save_pre’? Other hook?
- Filter question list on substring of metavalue
- Post are not showing up
- How to make post button to a random post
- Get results from the main wp_query
- Advanced Post Display/Pagination/Ordering
- Make assigning post to a specific category equivalent to assigning it to all categories
- How to use in_category?
- How to inject a post within a loop
- Sort by category and then date?
- Loop not allowing infinite scroll after post per page limit
- Customise the appearance of 4 specific post ID’s within the loop?
- what template-part to call, to have my post in the center of the page?
- How to show only the date, the title and a little “summary” of my WordPress post in my custom theme?
- How do I create a template page to show 3 blog posts?
- posts_per_page – Repeats only first posts ‘post__in’ array
- blog post displaying within older post – loop issue?
- Add custom PHP (no-SQL) filter to WP_query