Questions tagged [conditional-tags]

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

81 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
2 votes
0 answers
670 views

Adding Controls to Theme Customizer If Certain Page Template is Active

How to Conditionally add controls on Theme Customizer panel. Conditional like is_page() or is_page_template() obviously does/will not work because the page is being shown is customize.php. Code ...
Sisir's user avatar
  • 7,782
1 vote
1 answer
168 views

WordPress Block Editor Gutenberg running code inside ! is_admin()

In my functions.php I have some code inside a function that has a if (! is_admin) condition around it. For some reason the code inside this condition is running when I edit a page in the admin. Its ...
Jon's user avatar
  • 351
1 vote
0 answers
35 views

How add various functions within 1 conditional?

I want to add some gravity forms filters in my functions.php. I have the code up and running, but I would like to improve this snippet with a condition. As I only need these filters on 1 page of my ...
user3416348's user avatar
1 vote
1 answer
252 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 ...
juniorbra's user avatar
1 vote
0 answers
33 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 ...
Edegist's user avatar
  • 133
1 vote
0 answers
14 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 ...
Amir's user avatar
  • 11
1 vote
0 answers
811 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 ...
Shane's user avatar
  • 68
1 vote
3 answers
32 views

What do I add to this code to include additional CPTs?

I use the code below to add a message on the edit screen for a CPT 'item'. $screen = get_current_screen(); if($screen->post_type=='item' && $screen->id=='item') What do I need to add ...
glvr's user avatar
  • 881
1 vote
0 answers
800 views

How to write conditional for custom checkbox in featured image meta box

I have added a checkbox to the featured image meta box when editing pages/posts which will (if checked) add a custom css class that is currently stored as a variable to the featured image html on the ...
Benbodhi's user avatar
  • 105
1 vote
1 answer
214 views

Modify conditional titles to include parent and page number

Using conditional titles with title-tag rather than wp_title(), how do I add the immediate parent or ultimate grandparent to the title and,for multi-paged posts, the page number? When using wp_title()...
gulliver's user avatar
  • 123
1 vote
0 answers
125 views

Loading template parts conditionally in Customizer

Here are my issues: I have layout options in customizer for full width or two columns. For fullwidth sidebar will not be loaded. The problem is if the setting is currently on full width when ...
nonsensecreativity's user avatar
1 vote
3 answers
2k views

Google Analytics tracking code on just one page?

Having an issue where I have a client who wants his Google Analytics code on just one page. I'm using the following is_page code but in the footer.php of my child theme, but it's not appearing on the ...
Adam Bell's user avatar
  • 171
1 vote
0 answers
553 views

How to run filter only on custom post type edit screen

I am trying to force minimum width and height requirements on featured image upload on a particular post type only. My minimum width/height code is ok, as it works just fine on all post types. I am ...
lime's user avatar
  • 19
1 vote
0 answers
131 views

Conditional check for embedded video in the_content

I have a site where single.php displays the post stuff in this order: title featured image the_content I would like to remove the featured image IF the_content includes an embedded link (f.eg. to a ...
frafor's user avatar
  • 41
1 vote
2 answers
49 views

Conditional IF statement not returning true even though echo of $user->province is correct

I am having a problem with an if statement which I have now tested many times over. $user_query = new WP_User_Query( array( 'role' => 'Subscriber' ) ); if ( !empty( $user_query-&...
SixfootJames's user avatar
1 vote
1 answer
670 views

How can I hide the category term for posts with none set?

I'm trying to hide the word "Category:" from the metadata on the Twenty-Eleven theme's footer, when I don't have one set for a given post (sometimes I will manually remove the "Uncategorized" category,...
Azurite's user avatar
  • 31
1 vote
1 answer
597 views

Conditional statement for if archive page has posts which contain certain taxonomies/categories/tags, show those terms

I am using Isotope to filter posts on the fly from my archive pages. I have a Custom Post Type called "art". On the sidebar, I've created links to yearly archives on my sidebar, i.e. 2014, 2013, 2012....
Nataliette's user avatar
1 vote
0 answers
349 views

bbPress: How to set conditional for specific user -or- user role, to be displayed in user profile

I've been trying to set a conditional for specific users (e.g. http://www.mywebsite.org/forum/users/john/) to display a custom "Contributor" graphic within their user profiles. The graphic would be ...
user27459's user avatar
0 votes
0 answers
23 views

wp_tag_cloud: list only general tags associated with a custom taxonomy tag

I have a custom taxonomy called, for example, "colour". And I have normal tags. I use them both on posts. So, for a specific tag cloud I'm building, I want it to list all taxonomies that are ...
Nicodemus's user avatar
0 votes
0 answers
23 views

Wordpress blog post tags in 2 rows

In the WordPress theme I use, I can usually add 5-6 tags in one blog post. If I add more tags (7, 8, etc...), the tags continue to go under the sidebar, and don't make a second row (what usually the ...
DeeJay's user avatar
  • 1
0 votes
1 answer
35 views

Side bar only if it's not a single post or a specific page

I'm trying to make my sidebar appear only if it's 'not a post' or if it's 'not a specific page'. This is what I've tried. <?php if (!is_single() || !is_page('about') ) { get_sidebar() } ;?> <...
chrisrubb's user avatar
0 votes
1 answer
75 views

need help. plz help me. i cannot install wordpress

i cannot install wordpress. when i type localhost/my file name it showed - The requested URL was not found on this server. Apache/2.4.56 (Win64) OpenSSL/1.1.1t PHP/8.2.4 Server at localhost Port 80
rifa's user avatar
  • 1
0 votes
2 answers
307 views

Wrong site title and description in google search

as i said in the topic, i can't change the title and the description of the google search of my website (new website btw). I tried to change the title by Theme description, by wordpress settings and ...
Giorgio's user avatar
0 votes
1 answer
52 views

Custom post type is_singular condtional not working when managing sidebar display

I am using the if ( is_home() || ! is_page_template( array( 'template-investment.php', 'template-tourism.php' ) ) || ! is_singular( 'listing' ) ) { conditional to control the display of the theme's ...
Mike Hermary's user avatar
0 votes
0 answers
41 views

Is there any reason for the nested filters to be applied on the first case and not in the second one?

// This Works -> Filters are applied add_action( 'current_screen', function(){ $type = get_current_screen()->post_type; if(is_admin()){ // "true" add_filter('...
Joaquin's user avatar
0 votes
1 answer
41 views

How to Add text value in Automatically in this conditions?

**how to input a text value in this conditions automatically , when user input text fields value ** **which condition do I apply ? ** code was added :
spider's user avatar
  • 1
0 votes
1 answer
22 views

Target a page with query

I have those 2 pages that are created from a plugin (see the plugin https://zombify.px-lab.com/frontend-page/, just login and choose a post type, check the url): https://www.domain.com/post-create-...
Honoluluman's user avatar
0 votes
1 answer
797 views

Conditional if is single and part of the custom taxonomy

I want to write code only if it is single and part of the custom taxonomy. Here's how my custom taxonomy edit URL looks like: http://example.com/wp-admin/term.php?taxonomy=us_pf_category&tag_ID=53&...
akarim's user avatar
  • 305
0 votes
0 answers
32 views

Get value in TCPDF

I'm work on generation PDF from TCPDF in my current wp project, i have value: $v4 = unserialize(get_post_meta(get_post_meta($dog_id, 'nd_prod', true), 'np_str_ot_summ', true))[0]; in my TCPD i use ...
Lerry's user avatar
  • 111
0 votes
1 answer
304 views

Enqueue script if not page template

I'm using the following code in functions.php: if ( !is_page_template( 'page-full-width.php' ) ) { wp_enqueue_script( 'flickity-js', get_template_directory_uri() . '/js/flickity.js', array(), ...
Sam's user avatar
  • 2,126
0 votes
1 answer
89 views

Conditionally load public and admin code with AJAX working on both sides

I'm trying to conditionally load my front-end and admin area code, so the file and class that creates admin area will on load on admin side and file and class that is needed to be run on front-end ...
DaftPlug's user avatar
0 votes
1 answer
26 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 ...
question's user avatar
0 votes
1 answer
111 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 $...
heroj's user avatar
  • 13
0 votes
1 answer
89 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 = [...
hailton's user avatar
  • 101
0 votes
1 answer
268 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 ...
Myriam Richard's user avatar
0 votes
0 answers
19 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 ...
MJ2410's user avatar
  • 127
0 votes
0 answers
76 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 ...
samar's user avatar
  • 3
0 votes
1 answer
160 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" ...
Sunny K. Ujjawal's user avatar
0 votes
0 answers
487 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' ); ...
user avatar
0 votes
0 answers
344 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 ...
Capiedge's user avatar
  • 778
0 votes
0 answers
95 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 (...
De Coder's user avatar
  • 329
0 votes
1 answer
433 views

Generate Submenu based on Parent Page using If Statement

I need to pull a sub-menu depending on the parent page (or section) of the website. I have three sections (Our Inn, Our Restaurant, Activities) each requiring an individual submenu that my client will ...
Beau Beau's user avatar
0 votes
0 answers
33 views

$_SESSION Not working after X amount of page views

I've written up a simple function that's output into header.php, which displays the login/register modal upon so many views in this case I've set it at 4, however its firing on the first view of my ...
contempoinc's user avatar
0 votes
0 answers
533 views

method to fetch entire tag list on archive.php

What I have Tried → <?php $taginto = get_the_tag_list(); if ( ! empty( $taginto ) ) { echo '<a class="categum" href="' . esc_url( get_tag_link( $taginto[0]->term_id ) ) . '">' ...
WordCent's user avatar
  • 1,867
0 votes
1 answer
253 views

How do I apply different headers to different pages using this template?

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <header class="pagecontent-header"> <?php the_title( '<span class="entry-title">', '</span&...
user5597916's user avatar
0 votes
1 answer
1k views

Conditions for admin get_current_screen action parent_file edit.php?post_type=page

I have a plugin that requires scripts to load for an admin panel in the page-attributes template drop-down on page post type. However this script causes a Uncaught TypeError: on post post types ...
Jarod Thornton's user avatar
0 votes
1 answer
483 views

Widget Logic - display on page and all child

I have problem with condition function in Widget Logic (worpdress). I would like to display menu on subpage and all child set to it. I use this: global $post; return (in_array(1959,...
Pat's user avatar
  • 103
0 votes
1 answer
77 views

How to get number of posts in same category as current post?

I'm using the Widget Logic plugin to dynamically display a recent posts widget. This is the code I'm using: $thiscat = get_category( get_query_var( 'cat' ) ); $postcount = $thiscat->count; ...
jrcollins's user avatar
  • 571
0 votes
2 answers
35 views

What changes are needed for this conditional code to work on deeper levels?

I use conditional code to apply a css highlight to the menu item of a page currently being viewed. <li<?php if ( is_page('channels') || '2704' == $post->post_parent ) { echo " class=\"...
glvr's user avatar
  • 881
0 votes
0 answers
128 views

Page has no template

I've created a custom search for my custom posts, using the accepted answer from Creating a search form for custom fields. However, I'm struggling with the resulting page - I need to conditionally ...
gillespieza's user avatar
  • 1,275