If post author role is X

One way to do it is getting the author data and checking it’s role with get_userdata() Codex For that you will need the user ID, and you can get that with get_post_field() Codex You will need the post ID to use the get_post_field(), so you can use the get_queried_object_id()Codex So, you would have something like: … Read more

Show content after the first and second paragraph

My way to do this (see update below): function addParagraphs($content) { // you can add as many as you want: $additions = array( ‘<p>After 1st paragraph</p>’, ‘<p>After 2nd paragraph</p>’ ); $content = get_the_content(); $output=””; // define variable to avoid PHP warnings $parts = explode(“</p>”, $content); $count = count($parts); // call count() only once, it’s faster … Read more

Check if first paragraph is an image, then show custom code right after it?

How about a few simple lines With jQuery? jQuery(document).ready( function ($) { if ($(“.entry-content:first-child”).has(‘img’).length) //this check for the img tag $(“.entry-content:first-child”).after(“<div>MY CUSTOM CODE</div>”); else $(“.entry-content:first-child”).before(“<div>MY CUSTOM CODE</div>”); }); Update: Here is a simple solution using php’s native DOMDocument add_filter(‘the_content’,’add_code_before_afterImage’); function add_code_before_afterImage($content){ $MYCODE = ‘<div>this is my custom code</div>’; $doc = new DOMDocument(); @$doc->loadHTML(‘<?xml encoding=”‘.get_bloginfo(‘charset’).'”>’.$content); $ps … Read more