If you look at the source of get_the_term_list, you will see that it will try to get the terms first. If that doesn’t succeed, it will return an error or false. So you would have to account for that before you try to strip the tags:
if (!is_wp_error ($categories) && false != $categories)
$categories = strip_tags( $categories );
In all other cases get_the_term_list returns a string and your code should work fine.
By the way, it’s not very useful to have get_the_term_list to add <p> tags if you strip those away immediately. Also, there is a filter towards the end of get_the_term_list that you could use to strip the link tags that are added by the function. Finally, you may want to take a look at get_the_terms, which will give you a nice array of terms without any tags to strip.
Related Posts:
- Getting only direct child pages in WordPress with get_pages
- Query multiple custom post types in single loop
- Knowing the total number of posts before to get into the loop
- Build a content and excerpt grid loop with paging and options for # of posts
- How to loop over custom fields in a page template?
- Alter secondary loop to exclude posts from current page category
- Woocommerce, recognize the loop of related products
- Store loop into array
- Looping through WP_Post Object
- Easiest way to show total number of subpages
- Output 2 items within the Loop
- Show Custom Taxonomy Title
- How to exclude specific category from the get_the_category(); array
- spliting posts into two columns
- How to speed up a wordpress function with multiple loops?
- How to Display a Single Post Excerpt
- $wpdb->flush(); breaks the loop
- Use object in template part
- Get first URL from post content
- Changing layout with wp_customise
- Why my filterable portfolio page work not perfectly between slug button and slug output WORDRPESS?
- Iterate through posts based on array of categories
- get author_name from queried post
- How to add condition in wordpress loop? [closed]
- Alert Bar section within WP loop is displaying even though there are no posts
- Checking array against author id in loop
- How do I Turn This Into An if statement?
- Load wordpress content in other domain
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- post thumbnail, conditions, else wont work
- wp_query get the 2nd post
- I’m trying to create an array with a foreach loop, but the array only stores the last item [closed]
- How to avoid duplicates when creating recent network posts
- Why in my theme I can’t see all the statics content under the posts?
- variable value disappears in a second loop
- How to unlink all posts from tracking same amount of views
- Why my loop isn’t working? [closed]
- How to pass current loop data into nested loop
- Get all posts as an array ID => Name
- How to get post ID from button and pass title to Modal
- Problem with custom loop and wp_list_pluck [closed]
- Display child page content of a specific parent on home page
- Do not duplicate posts with multiple categories in multiple loops
- Infinite Loop – WP_Query
- How to wrap every 3 posts in a div (and close the last div too) [closed]
- Dividing the loop to style post differently
- WordPress loop is not working
- First post article different on Archives template
- How to add title attribute to archive items
- Strip from or something better?
- Problem in replacing the_content with the_excerpt()
- Search AJAX Filters – Multiple Query Loops Into One Loop (Optimization)
- Pagination contents not changing in Front page WordPress
- in_array not working on dev server but works on localhost
- How to Create Carousel Indicators in PHP Loop using wp_get_attachment_url function?
- Get title of page containing post grid within the posts
- Is there anyway I can call the year once?
- Display all categories including sub categories under a list ul
- Foreach Loop Of Post Types With Nested If Else If Not Completing Process
- Where does php code to load data go?
- Adding new divs with custom classes to products on WooCommerce shop page [closed]
- cURL needing to loop through all “next_page”
- Display page content in different sections – based on page break block?
- Filtering custom posts by using checkboxes for taxonomy in an ajax loop always gives server 500 error
- Latest posts feed with a specific post always first
- Show the subcategory name based on current product
- How can I get my pagination loop to display the correct number of total pages?
- Making list of posts with chosen description
- Get current_post in reverse order with pagination
- How fix error in the WordPress loop?
- Efficient way of querying for a “fallback” post?
- Div Missing In Custom Loop Query
- Loop 1 user randomly
- Create a hierarchical loop at predefined markup requirements
- enumerating custom taxonomies?
- Using page template to fetch posts in page
- Create Customization Controls from Array
- Problems With Query and/or Template Part and/or PHP
- Two loops in one function
- ACF loop and php formatting
- How to display thumbnail if post is assigned one otherwise not
- Pagenav Not appearing on custom Template
- Error trying import one category on page
- Remove the_content From Loop
- Custom Meta Box If Else Statement
- Adding if statement to content for homepage
- Tables not showing divs and loop/php items
- Alternative loop syntax error [closed]
- Pagination in category.php not functioning
- For each loop will not append to the_content hook
- How to handle parent and child pages?
- How do I remove blog entries from home page Twenty Eleven child theme?
- How to create a loop that will display one post and stop?
- Woocommerce linking variations
- Pagination not working properly
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- Saving meta box data from selected option’s value in database is not working
- When a foreach loop is used multiple times in blocks, is there a way to ensure a variable always has a unique value?
- Custom theme on multisite has issues with standard loop output
- How to get the post title inside a custom block in a loop? block.js