Condition function for is parent category?

I’m not sure I fully understood your question, but wrapping a function inside a new function will make it shorter. For example, do the following in your functions.php file: function is_parent($slug){ if(is_category($slug)){ return true; }else{ return false; } } And then simply use it like: if(is_parent(‘slug’)){ // do something }

Loading Scripts on Specific Pages

I’d suggest moving the script registering into the init action, and moving the enqueue(s) into a callback hooked onto wp_print_scripts. Eg. add_action( ‘init’, ‘register_those_scriptsNstyles’ ); function register_those_scriptsNstyles() { wp_register_script( .. your script params .. ); wp_register_style( .. your style params .. ); ..etc.. } add_action( ‘wp_print_scripts’, ‘enqueue_those_scriptsNstyles’ ); function enqueue_those_scriptsNstyles() { if( !is_page( ‘some-page’ ) … Read more

Add default content to posts in a specific category?

Using the code you posted, the selected category’s ID is available in the $_REQUEST, you can check that ID against your products category in the default_content filter and add content if there’s a match: add_filter( ‘default_content’, ‘wpa70073_default_products_content’ ); function wpa70073_default_products_content( $content ) { // change this to your desired category ID $products_category_id = 42; if( … Read more

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

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)