A simple method for disabling WPML language switcher when meeting specific circumstances [closed]
A simple method for disabling WPML language switcher when meeting specific circumstances [closed]
A simple method for disabling WPML language switcher when meeting specific circumstances [closed]
If it is about child post types* or taxonomies**: // page/post/cpt parent check: $post_object = get_queried_object(); // check if the page has a parent if ( $post_object->post_parent ) // do stuff // cat/tax parent check: $taxonomy_object = get_the_category( get_query_var(‘cat’) ); // check if the cat/tag/tax has a parent: if ( $taxonomy_object->parent ) // do stuff … Read more
If the page slug is ‘contact’ then is_page(‘contact’) should work. You can check out the optional parameters for page in the codex here . Using post ID, e.g. 94 in your example will work regardless of permalink settings. If you want it to display for a specific template you can use is_page_template(‘contact.php’).
You can rewrite you code as <title> <?php if (!function_exists( ‘is_product_category’ )) { if( is_product_category( ‘cds’ ) ) { ?> CD <?php } elseif ( is_product_category( ‘dvds’ ) ) {?> DVD <?php } }else { wp_title( ‘|’, true, ‘right’ ); } ?>
Use get_post_ancestors(): // get page ancestors $parents = get_post_ancestors( $post->ID ); // id of parent page you want to find $parent_id = 123; // check of $parent_id if ( $post->ID == $parent_id || in_array( $parent_id, $parents ) ) { echo ‘<a href=”#”>Link</a>’; }
You can use the has_category() function for this: if ( has_category( ‘Grizzly Bears’ ) ) { get_header( ‘header2’ ); } else if ( has_category( ‘Peace Pipes’ ) ) { get_header( ‘header3’ ); } You can add the has_tag function as well. Both accept an array of term IDs, names or slugs if you want to … Read more
You can also get slug from direct post parent id like: $parent_id = $post->post_parent; $post_parent_slug = get_post_field( ‘post_name’, $parent_id ); Now you can replace: ‘2’ == $post->post_parent to ‘notes’ == $post_parent_slug Try this.
You can use a conditional tag to check if the user is logged in. Conditionals are very common in W, I would suggest you give this page a read. Here is an example. function footer_shortcode(){ if (is_user_logged_in()){ echo ‘ // Logged In Content ‘; }else{ echo ‘ // Logged Out Content ‘; } } add_shortcode(‘footerShortcode’, … Read more
Your real problem is the god class. You put rendering, sanitation, validation, saving and fetching data, and registration into one class. Separate your tasks to make it it OOP, and let the main class be a very simple front controller that handles the initial registration only. Here is a rough start, illustrating how I would … Read more
You can define a global variable in your theme functions.php global $mywidgets; $mywidgets = false; in your template part add global $mywidgets; $mywidgets = true; and in your functions you can check if its set to true: function my_function(){ global $mywidgets; $mywidgets = true; if ($mywidgets){ // YES Your template part is loaded }else{ // … Read more