Questions tagged [conditional-tags]

functions that return a single boolean value depending on what is currently being viewed

Filter by
Sorted by
Tagged with
0
votes
1answer
22 views

Regarding Tags And Categories

I wanted to use a new theme for my website, but the problem is, in my current theme, it has spesific tag like for example "abc tag" and in my new one, it doesn't. So if I change my theme, all the ...
1
vote
1answer
26 views

WooCommerce Conditional Tag inside plugin

I'm writing a small plugin to add some text above the 'Add To Cart' button on the WooCommerce product page. My code: add_action('woocommerce_before_add_to_cart_button', 'ddd_above_add_to_cart', 100);...
1
vote
1answer
21 views

Display a div only in some author's single posts

I'd like to display some information inside a div on the single posts written by some authors. For exemple, author ID 15 has 100 posts. I'd like to display some information on that post pages, just ...
-1
votes
2answers
141 views

Conditional statement with three condition

I am trying to write an if condition with 3 statements but it keeps crashing the site. Here is my statement, can you please advise what the issue is. <?php if (is_page ('20')){?> print this <...
1
vote
1answer
30 views

How to pass conditional array to wp_localize_script

I'm trying to generate a custom array from a PHP function to pass on wp_localize_script but I seem to not be able to set page conditionals. I have the following function: function ...
0
votes
1answer
29 views

Showing taxonomy terms on custom post type

I have a custom post type named movies and taxonomy is genres. Now there's a movie "random" with genres "horror" "drama" "adventure" What I want to do is: list all of the associated genres on that ...
1
vote
0answers
10 views

Conditional query that displays on Woo product attribute pages

I have a custom query set up that currently modifies the product category pages of my website. I would also want this code to affect the product attribute archive pages of my website, but I am having ...
0
votes
1answer
22 views

has_category() for parent category

Is there a way to make a condition for posts belonging to any sub-categories of a given parent category? Here is an example, assuming the following category structure: News FAQ 1) Installing 2) ...
0
votes
2answers
132 views

is_product_category('Services') not working

I'd like to hide the "add to cart" & price for WooCommerce products in the 'Services' category. I've tried the following code in my child theme's functions.php, but https://pureblissmoonhealer....
0
votes
1answer
19 views

Content visibility condition based on date

How can I use visibility condition for displaying post no older than 30 days as described here: https://docs.dynamic.ooo/article/58-visibility-triggers-custom-condition I try something like this $...
0
votes
1answer
39 views

Filter for the Custom Post List Page

I'm adding a filter on my custom post type 'book' list page for easier searching. I've found the relevant code and everything is good except that the filter not only appeared on the 'book' list page, ...
0
votes
2answers
29 views

How to show only specific tag in wordpress loop

I am trying to get the loop to show only two tag that have the ID 53 and 52. the code without the "if is_tag( array( 53, 52 ) ){" works. I tried different thing but I can't get it to work. Thank you ...
0
votes
2answers
19 views

Add code to the header of posts by particular author

I want to add CSS code to the header of all the posts by a particular author. I tried the following solution: function hide_author_box() { if (is_author('ritesh')) { ?> <style> ....
0
votes
1answer
36 views

How can I check the rewrite slug of current post type listing page

Supposed I have these urls: http://my-domain.tld/projects-listing-cpt and http://my-domain.tld/musics-listing-cpt. The custom post types was setted this way: Projects: Text Domain: projets $args = [...
0
votes
0answers
108 views

Set “woocommerce_is_purchasable” to false for specific “$product->is_stock_status”

I created a plugin to add a new stock status to my woocommerce products. I used this as my reference (copy and pasted into my plugins php file): Create WooCommerce custom stock option that is non-...
0
votes
1answer
33 views

Display specific page if user signed in

I have a business directory website. I'd like to know how to create a page display condition. Basically, when clicking on the "add a listing" button, how do I make non-logged-in users be directly ...
1
vote
1answer
44 views

Remove meta box for specific page

I'm trying to conditionally remove the 'Page Attributes' meta box for a specific page (or multiple specific pages). For example: function remove_meta_boxes() { if (is_page('contact')) { ...
0
votes
0answers
17 views

Add user tag to corresponding custom posts

I use The events calendar plugin as a timetable for scheduling staff. Each event (custom post) represents a shift. Each event title (post title) is named after the particular employee of that shift (...
0
votes
0answers
16 views

Add an identifier to a set of pages to access using a conditional tag

For my website, i need to add a particular css file for a set of pages in wordpress which I am trying to do from functions.php. For example: This is a set of PAGES and not of type post. All these ...
0
votes
1answer
58 views

Conditional tag doesn't work in WordPress plugin

I'm developing a plugin which can change the whole content of a special page in WordPress with an image. My plugin's code is here: <?php /** * Plugin Name: Test1234 */ function set_header_page()...
0
votes
2answers
19 views

why str_replace targeting pages instead just targeting post?

I am trying to replace a word only on post pages. The issue I am running into is that WordPress page content ends up blank even though this code should only run on post pages. <?php /** * ...
0
votes
2answers
30 views

Modify wp-login.php Labels Conditionally Based On Referring URL

I apologize if this is an easily answered question - I've been looking for a while and can't quite get my head around it. I would like to modify the first label for the wp-login.php page based on the ...
1
vote
1answer
216 views

Edit css for search results page

I have a search results page with a template call content-search.php. Basically what this file does is to display the results after a person searches something on the search bar, and i would like to ...
-1
votes
1answer
47 views

IF taxonomy archive is hierarchical THEN

I'm trying to put in a conditional in my archive.php that sorts our whether the taxonomy is hierarchical or not. This is what I have so far but it doesn't work. <?php if ( is_taxonomy_hierarchical(...
0
votes
1answer
29 views

Changing Post Tag Color Based On Post Count

I have post tags that must always display. I want to change the color of the tag if there are no posts. I am looking for guidance on how to find the count and change the color of the post tag link ...
0
votes
2answers
50 views

Sidebar by Category Conditional Statement not functioning

I have two categories for my posts, "event" and "long-term-leasing." I have sidebar-events.php and sidebar-long-term.php. I wrote a conditional statement in single.php, but when I view a post it only ...
0
votes
0answers
33 views

How to get Post sidebar & footer including html like get_the_content() which only gets content section?

I want to get sidebar & footer including html of current post. Then I want to check a "string" inside sidebar & footer. If "string" exits, I want to enqueue a custom script. If anyone knows ...
1
vote
2answers
147 views

Display Footer Shortcode Different for Logged In Users

I have a shortcode that displays a block of content. Is there a way I can display different HTML depending on if the user is logged in or not? Below is what I have so far. function footer_shortcode(...
1
vote
0answers
10 views

Conditional Tags Based on Previously Viewed Posts

I was looking at the Conditional Tags Archive and was wondering if it's possible to show a widget depending on different posts / pages a visitor has previously viewed. For example, if I had a car ...
0
votes
1answer
208 views

How to target a search result page?

I'am wondering how to target a search result page within the functions.php file in wordpress. I know about "is_search" for the search page but what about the search result page ? Can we put a ...
0
votes
1answer
38 views

How to add custom PHP code in post header?

In header.php i want to add : 1. For home page : link rel="alternate" href="/fr/" hreflang="fr-FR" 2. For custom single post : link rel="alternate" href="/fr/category/post-name/" hreflang="fr-FR" ...
2
votes
1answer
165 views

When is is_admin() available?

I see a lot of plugins that consist of a class that is instantiated in the same file, eg: class My_Plugin { function __construct() { add_action('init', array( __CLASS__, 'baz' ) ); } ...
0
votes
1answer
105 views

How to get value from radio buttons meta box, and return different contents?

I have a multiple checkbox type question (using Ultimate member) storing values as user meta. The question basically asks the user what he wants, and according to what he wants, I would like my ...
0
votes
0answers
69 views

adding an action inside if condition not working

This is my function $enable = false; //if false is provided then the action should run and remove the breadcrumbs if($enable ===false){ add_action( 'init', 'woo_remove_wc_breadcrumbs' ); ...
0
votes
2answers
354 views

I need use is_single in functions.php

I need to use validation is_single('wordpress') in file functions.php. But the function is_single() does not work in the file functions.php. What can I do so that I can use is_single() in file ...
0
votes
0answers
72 views

Why is_page() returns false when visiting the static page declared as “posts page”

First of all, sorry if this is a duplicated question... But I haven't found it in the same terms as I'm asking. I'm surprised because when checking the conditional is_page() in a function executed ...
1
vote
0answers
40 views

How To Conditionally Include A Short Code Depending On The HTTP_REFERER [closed]

I want to show a form at the end of my purchase-confirmation page only in the case where the previous page / HTTP_REFERER is the checkout page. I've tried lots of different ideas. For example, I was ...
0
votes
0answers
43 views

is_page not triggering

Here is my code: add_action('template_redirect', 'ep_tags_redirect_lockout'); function ep_tags_redirect_lockout() { if ( is_user_logged_in() ) { return; } //echo 'XXXXXX'; if (...
1
vote
1answer
36 views

Calling is_single() outside the loop

The file required doesn't load on single posts, it doesn't load anywhere! If I removed the is_single() function I can get it to work. My question is how I can check if the current page is a post? I ...
0
votes
1answer
20 views

Alt Image Wordpress [closed]

When I use a seo tool in my blog, the tool has a lack of alt in the image of the site logo, but only in the urls of the posts (in the homepage the tool can identify the alt of the logo, which is the ...
0
votes
1answer
315 views

Undefined index for default custom theme option

I have a custom theme option that allows the changing of logos. There are 3 logo options: option1, option2, and option3. Upon theme activation, the default "option1" logo appears, but above it I get ...
0
votes
2answers
176 views

is singular and is home not working

I am creating a theme and i have added custom hooks to make the developement easier. when using the code in functions it works in all pages. the code is below add_action('before_footer','...
0
votes
2answers
33 views

Additional conditions tags to work

Im trying to get this simple condition tag to work . Im having no luck // If we are logged in, and NOT an admin and NOT on specific page... if ( is_user_logged_in() & !is_admin() ) & !is_page(...
1
vote
0answers
367 views

Wordpress, AJAX and pre_get_posts using conditional tags

I have a page that returns a list of posts in a custom post type. This is generated by a third party plugin. I want to omit the posts that are using a custom post status 'template'. Really the only ...
0
votes
1answer
718 views

Gravity Forms, multiple conditions in shortcode

Gravity forms offers a shortcode for conditional display based on responses. [gravityforms action="conditional" merge_tag="{:3}" condition="less_than" value="30"] Your value is less than 30 [/...
2
votes
1answer
143 views

How to check if an action is already fired?

How to check if an action is already fired in a function for example: function foo() { // checking if the action 'wp' is fired if( !action_fired('wp') ) { trigger_error('invalid call'); ...
0
votes
2answers
28 views

Can this code be concatenated?

I realise this is perhaps more of a php question, but it relates to WP use. Can the example below, be modified (and if so, how?) to fully concatenate the 2 echos rather than having them separate? if....
0
votes
1answer
296 views

How to add theme customizer control to specific page?

I would like to have something like: if (is_post_type_archive('my_post_type')) { $wp_customize->add_section(...); $wp_customize->add_setting(...); $wp_customize->add_control(...);...
0
votes
1answer
245 views

Why is this is_page conditional not working?

I am trying to do something I thought would be fairly simple. But it's not working, and has me stumped as to why. Any insight would be appreciated. I have a custom /woocommerce/archive-product.php ...
0
votes
1answer
54 views

Remove conditional tag from header

<?php if ( get_theme_mod( 'fukasawa_logo' ) ) : ?> <a class="blog-logo" href='<?php echo esc_url( home_url( '/' ) ); ?>' title='<?php echo esc_attr( get_bloginfo( 'title'...