How to get category id in single.php wordpress?

Use wp_get_post_categories() Retrieve the list of categories for a post. <?php wp_get_post_categories( $post_id, $args ) ?> Be aware that the function returns an array (of category ids) even if you only have one category in your post. The example below shows how categories are retrieved, and then additional information is retrieved for each category. $post_categories … Read more

Add inline style to get_the_category_list

get_the_category_list() does not really have any filters to achieve what you want. You will currently need PHP like preg_replace() to alter the anchor tags. The big issue would be to get the current link’s term object, which in my opinion would turn it into a quite messy procedure. You could however write your own function … Read more

if is_singular array not working as expected

You are using an incorrect check here. is_singular() returns true when a post is from the specified post type or post types or the default post types when none is specified. You cannot target specific single posts with is_singular() You have to use is_single to target a specific post if ( is_single( ‘post-a’ ) { … Read more

if post id matches these id’s then do this

This looks almost correct. Let’s have a look at is_single(): Works for any post type, except attachments and pages… So if the given ID isn’t that of a page or attachment post type then you can use the function as so: if( is_single( 2578 ) ) { /* … */ } else { /* … … Read more

Insert After Second Paragraph Without Tag?

I need to stress that I think this is going to be very unstable and you may not always get the results you want, but in simple cases this should work. $content = apply_filters(‘the_content’, get_the_content()); $content = explode(“</p>”, $content, 2); // var_dump($content); // debug echo $content[0].'</p>’; echo ‘<div>Extra Content</div>’; if (!empty($content[1])) { echo $content[1]; }

Show single post then all posts (with pagination)

Pagination does not work well will with secondary queries. First, the ordinary pagination functions depend upon the main query in the global variable $wp_query. They won’t work with secondary queries. There are already a number of questions here about that if you search the site. Second, trying to paginate secondary queries tends to result in … Read more