Display a div when post has a certain tag

You could use a simple conditional and check if the post has a term using has_term(): has_term( $term, $taxonomy, $post ); Pass in your Term Slug, the taxonomy ( which sounds like you’re using post_tag and the post object, no javascript needed. <?php if( has_term( ‘term_slug’, ‘post_tag’, $post ) : ?> <div> Show your div … Read more

If page displays posts conditional

Both will do the same job in the end of the day. You can however improve on the first code. is_archive() returns true on all archives page, which includes the following taxonomy archive pages category archive pages date archive pages author archive pages tag archive pages So, if you need to target all these pages, … Read more

Conditional Statement with Multiple Terms?

Firstly, create some sort of association between the icon class and the term name: $icons = array( ‘webinar’ => ‘fa-desktop’, ‘report’ => ‘fa-file-text-o’, ‘video’ => ‘fa-youtube-play’, ‘past-project’ => ‘fa-cogs’, ‘meeting-material’ => ‘fa-users’, ‘info-sheet’ => ‘fa-info-circle’, ); Then loop through each term assigned to the post and output the corresponding icon: $terms = get_the_terms( get_the_ID(), ‘type’ … Read more

Why is this is_page conditional not working?

“Bangles” isn’t a page. It’s a Product Category Archive. is_page() checks: Is the query for an existing single page? Which product categories are not. See the Template Hierarchy to get an idea of the different types of ‘pages’ in WordPress. If you want to check if you are viewing a product category archive, use is_tax(), … Read more

Conditional tag doesn’t work in WordPress plugin

Both those hooks are too early to use is_page(). WordPress hasn’t determined which page is being loaded yet, so it can’t check the current page. Try template_redirect for both: /** * Plugin Name: Test1234 */ function replace_image_content(){ if ( is_page( ‘img’ ) ) { header( ‘Content-Type: image/jpg’ ); $image = plugin_dir_url(__FILE__) . ‘1404-1.jpg’; readfile( $image … Read more

Wrap the_title_attribute in a H2 within a Conditional Tag?

The the_title_attribute() template tag is intended specifically for outputting the Title formatted for use in an anchor tag title attribute. The the_title() and get_the_title() template tags are intended for general print/display of the Title. I would recommend using get_the_title(), rather than the_title_attribute(). To wit: elseif( get_post_type($post->ID) == ‘press’ ){echo'<h2>’. get_the_title() .'</h2>’;} I believe this would … Read more

do add_action on condition

Use has_category() to check if a post belongs to a certain category. function email_friends( $post_ID ) { if ( has_category( ‘uncategorized’, $post_ID ) { $friends=”[email protected], [email protected]”; wp_mail( $friends, “sally’s blog updated”, ‘I just put something on my blog: ‘ . get_permalink( $post_ID ) ); } } add_action(‘publish_post’, ’email_friends’); And you don’t need to return anything … Read more

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