single-{post_type}.php not working

according to your code, your cpt is “event”. You will either need to change the your php to single-event.php or change this line: register_post_type(‘event’, $args); to register_post_type(‘events’, $args); Usually they are the plural so the 2nd option is a better choice. With that being said, I always recommend adding namespace to avoid conflicts. Especially in … Read more

Insert sometext after first h3 in content

Note returning $content[0]; when !is_single() you’ll get non-exist errors. You can accomplish what you’re after with somthing like: add_filter(‘the_content’, function ($content){ if (!is_single()) return $content; $div = “🎅🏻”; return preg_replace(‘/<\/h3>/i’, “</h3>”.$div, $content, 1); }); note the third parameter of preg_replace() is the limit, setting to 1 will restrict the replace to the first match.

WordPress block editor embeds not working in theme (single.php)

That would be because they’re using oEmbed, not a shortcode. You should use the function the_content() to render the content of a post, as it applies all the things required to make embeds, shortcodes, etc work properly. If for some reason that’s not an option, you can apply the content filter. <?php echo apply_filters( ‘the_content’, … Read more

Custom seperate Single.php

This should help, if you need more info: http://codex.wordpress.org/Template_Hierarchy Simply put, WordPress looks for template files in the following order for single posts: single-{post_type}.php, single.php, index.php. If you want to override the standard single.php file, that’s how (for a custom post type only, as you’re using)

Single page not working for custom post type

Add this to your functions.php: /* Flush rewrite rules for custom post types. */ add_action( ‘after_switch_theme’, ‘bt_flush_rewrite_rules’ ); /* Flush your rewrite rules */ function bt_flush_rewrite_rules() { flush_rewrite_rules(); } Then change your theme to a different theme and then set it back again to your custom theme. This will flush the rewrite rule and making … Read more

the_excerpt() in content.php and get_template_part() in single.php

the_content() does not grab the PHP file content.php, it simply displays a Post’s content. Likewise, the_excerpt() grabs the excerpt of a post. get_template_part simply finds a file within your theme named whatever you put in, with an optional suffix. get_template_part( ‘content’ ); // content.php get_template_part( ‘content’, ‘my_page’ ); // content-my_page.php in order for make different … Read more

Single.php – Get Current Parent Category

The very broad answer for why this doesn’t work is that the internet is stateless. Basically each request for a page is a separate and unique instance from other page requests. Example Let’s say post-1 is in category-1 and category-2. When WordPress loads post-1 on single.php it has no way of knowing how the user … Read more