Add_action to wp_head via functions.php

I installed the Twenty Seventeen theme and a child theme. Now I want to add the following code to functions.php to add meta data to the <head> tag using the wp_head action: if ( is_single() ) echo get_post_meta($post->ID, “meta-head”, true); ?> I tried this, but it did not work: add_action (‘wp_head’,’hook_inHeader’); function hook_inHeader() { if … Read more

Check IF is a “single product page” and Check the “role” for a Redirect

After much research on the net, I have not found a solution that works. Do you know how can I do that on woocommerce : I try that for the moment : function cm_redirect_users_by_role() { $current_user = wp_get_current_user(); $role_name = $current_user->roles[0]; if ( is_products_page() && is_single() ){ if ( $role_name === ‘customer’ ) { wp_redirect( … Read more

Conditional for single-{post-type}.php

Please help with this code for custom post type “video”: If is single-video.php page { list custom-taxonomy of video. Example actors } Else { do nothing } I´m tried with is_single, is_singular, is_page_template but imposible. 1 According to the WordPress conditional docs it should be: if ( is_singular( ‘video’ ) ) { // do conditional … Read more

How to detect single.php (but not single-portfolio.php)?

When I’m using is_single(); in my <head> section to add some style to website navigation it executes correctly on blog posts but it also executes on single “portfolio” post type posts (so single-portfolio.php and single.php). How do I make it execute only on single.php? 2 You can use the following instead, if (is_singular(‘post’)) { //your … Read more

Custom post type single-{custom}.php not working

I made a custom post type with the machine name special_media_post and wordpress is simply not seeing the single-special_media_post.php. I am at a complete lose. It keeps defaulting to the index.php Here is my code for my custom post type and its taxonomies: //Post and Taxonomy stuff //Register Custom Post Type function special_media_post() { $labels … Read more

How to check if the product is in a certain category on a single-product.php in Woocommerce?

How in the world can I check if a product is in a certain product category on the single-product.php? <?php if (is_product_category(‘audio’)) { echo ‘In audio’; woocommerce_get_template_part( ‘content’, ‘single-product’ ); } elseif (is_product_category(‘elektro’)) { echo ‘In elektro’; woocommerce_get_template_part( ‘content’, ‘single-product’ ); } else { echo ‘some blabla’; } ?> is_product_category(‘slug’) does not have an effect … Read more