Skip to main content

Questions tagged [conditional-tags]

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

Filter by
Sorted by
Tagged with
1 vote
1 answer
63 views

WooCommerce: Custom dropdown for variation selection

In WooCommerce, I have an attribute called License Type. This attribute has 2 terms: Single Site License Multi Site License With the above, I'm trying to create a custom select dropdown, where the ...
Freddy's user avatar
  • 167
0 votes
0 answers
28 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
1 answer
43 views

How to make my scroll bar show under condition

I am using WP/code snippet with my wordpress website (here still on localhost) and I have a scroll bar that I want to show only when we add the text that will contain this scrollbar at the top. I have ...
Mehdi's user avatar
  • 103
0 votes
0 answers
29 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
54 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
79 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
463 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
1 vote
1 answer
264 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
  • 325
1 vote
1 answer
44 views

Wordpress show content if current user get spesific role and spesific meta value

How to make conditional if statement like "Show content if current user get spesific role and spesific meta value", if not.. hide content <?php if( ( current user get spesific role and ...
Tuagapat Manam's user avatar
0 votes
1 answer
93 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
1 answer
90 views

Getting false for is_home() on Posts page

I've made a child theme of Twenty Twenty theme and want to display the posts/ category archive pages in flexbox grid. However, none of the conditional tags I'm hoping to check outside the loop (...
MikeiLL's user avatar
  • 579
1 vote
2 answers
2k views

check if post is set to "password protected"

I'm trying to find a way to show different content if a post is set to "password protected", once the user entered the correct password. I want to show the price of an art piece only on ...
user2882154's user avatar
0 votes
1 answer
2k views

PHP Notice: Function is_page was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false

In my functions.php I have: // Load Google Optimize script in head function us_homepage_optimize_test() { $site_id = get_current_blog_id(); if(is_page(10) && is_main_site($site_id)) { ...
Steve's user avatar
  • 1,747
0 votes
0 answers
47 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
162 views

check that the data exists before sending it to wpdb

When I send data to wpdb from form I can have some empty fields. How can I add conditions to array of data inside array or before insert wpdb to send only filled fields ? The fields concerned (for ...
imagIne's user avatar
  • 105
0 votes
1 answer
44 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
1 vote
1 answer
643 views

What is the practical difference between is_admin() and is_blog_admin()?

I can see that the 2 functions are almost identical. Only difference is in one line: @is_admin() return $GLOBALS['current_screen']->in_admin(); @is_blog_admin() return $GLOBALS['current_screen']-&...
Viktor Borítás's user avatar
1 vote
1 answer
568 views

Enqueue scripts not working with if is page conditional tag in functions.php

Is this even the correct way of including scripts on a specific page? function insert_mapsvg_scripts() { wp_enqueue_style( 'mapsvg_css', site_url('/mapsvg/css/mapsvg.css') ); wp_enqueue_style( '...
Biels's user avatar
  • 113
0 votes
1 answer
39 views

How to not display tags with less than X posts

Is there a way to avoid displaying tags which have less than X Posts? the answer here is close Remove from Google Tags with less than 2 posts however it suggests to send a respose header to google. I ...
shelbypereira's user avatar
1 vote
0 answers
36 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
0 votes
1 answer
252 views

Should $query-> be used with conditional tags?

The function below limits the search results to posts only. function exclude_pages_from_search_results( $query ) { if ( $query->is_main_query() && $query->is_search() ) { $...
Ryan's user avatar
  • 63
1 vote
1 answer
118 views

Conditional secondary menus

I have a main menu of 3 items, and for each of these I have a different secondary menu. I would like to show the related secondary menu on each page. I currently used is_page with slug. I will need to ...
Vinz Clortho's user avatar
0 votes
1 answer
612 views

How to: Conditionally Enqueue JS and Stylesheets, for Custom Post Type (Single and Archive Templates)

I’ve created a plugin for my child theme, in which custom functions are stored. Additionally, within the plugin, I'm also enqueueing stylesheets and .js which control the output of two templates, for ...
Nate's user avatar
  • 15
0 votes
1 answer
121 views

How to add Text before my Custom Term and hide it when empty

This is my code: <?php $terms = get_the_terms( $post->ID , 'this_is_custom' ); $links = []; foreach ( $terms as $term ) { $term_link = get_term_link( $term, '...
Taufan's user avatar
  • 3
0 votes
1 answer
4k views

How to change WooCommerce loop product title HTML output in single product page and archive page

I'm currently working on designing my custom WooCommerce theme and wondering how I could change the HTML output of loop_product_title in single product page and in archive pages. I have less knowledge ...
Chotu Kaalia's user avatar
0 votes
1 answer
921 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
1 answer
187 views

How should I be using filters and is_single together?

I have a plugin that uses this filter to add some content to a Custom Post Type. // From plugin: add_filter( 'the_content', 'sixtenpresssermons_get_meta', 15 ); I'd like to remove that filter on ...
Anders Carlén's user avatar
0 votes
1 answer
463 views

issue with if/elseif in_array inside foreach loop display only one post

I try to attribute a specific background-color to each post if one of categories of post corresponding to one category. My function works but is restricted to display only one post in result. If I ...
imagIne's user avatar
  • 105
2 votes
2 answers
591 views

Limit posts only on home page - ideally in functions.php

I'd like to restrict the number of posts that show on my home page to 3, but have all the other archive, category, pagination pages, etc. at whatever number I set in the "reading" settings ...
Lori L's user avatar
  • 21
1 vote
0 answers
94 views

A simple method for disabling WPML language switcher when meeting specific circumstances [closed]

this is not a question but -hopefully- an answer. I realized that more than a couple of people on the WPML forum asked for a solution to this matter, so I thought it could be useful to share my ...
Marks's user avatar
  • 31
0 votes
1 answer
1k views

Conditional to determine if search.php page is the current template

I have a specific CSS-file for my search results, so the search.php template. I want a PHP if-condition to determine if the current template is the search.php template, so that I can load that CSS-...
ralphjsmit's user avatar
0 votes
0 answers
33 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
1 vote
1 answer
3k views

How to enqueue CSS and JS only on specific template?

I'm busy with my home.php template and I need a few CSS/JS files that are only loaded on that specific template. I tried doing it with if ( is_page_template( 'home.php' ) ) { //ENQUEUE CODE }, but ...
ralphjsmit's user avatar
0 votes
1 answer
83 views

How can i create a function tag in my plugin

I want to know how what function or hook i can use to create a php function that executes as tags like this [block] content to be blocked[/block] my function will start with [start] afftected ...
pandglobal's user avatar
0 votes
1 answer
335 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,166
0 votes
1 answer
123 views

is_front_page() variable not found

I am trying to do what should be really simple, but somehow this is driving me mad. I try to have a code snippet only run on the front page. My site is set to have a static front page so I think my ...
Dosenlunch's user avatar
1 vote
2 answers
88 views

How do I style Wordpress pages differently based on the tag used?

I was thinking this might be done by adding custom CSS to a page template. I have a page template like this: <?php /* * Template Name: Grafy Full Width */ /*add_filter('...
Kristýna Šulcová's user avatar
0 votes
1 answer
91 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
364 views

Echo text using is_tag

I've been trying to echo some text to all single pages that are part of tag_ID 129 This is the code that I used <?php if ( is_tag( '129' )){ echo '<p> test 2</p>'; } ?> so ...
Alex's user avatar
  • 1
0 votes
1 answer
655 views

is_tax() conditional tag not working

I have a menu item where a CSS class is added with a 'page_active' class (which visually shows an underline under the relevant item). This is added on certain menu items if the is_page('Latest') or ...
pjk_ok's user avatar
  • 908
1 vote
1 answer
2k views

Display message if no posts in Custom Post Type loop

I am trying to get this thing to work, but can't figure out where is the problem. I added else statement, but it does not work. I was able to get this work with jQuery, but I need it to work in PHP as ...
TheRoyality's user avatar
3 votes
1 answer
4k views

Allow users with Editor role to edit menus (without a plugin)

I came across the need to have a site Editor to edit menus. I found some answers that suggest the add_cap() approach, to add the edit_theme_options capability to Editor role. This should be done once ...
alvarogois's user avatar
0 votes
1 answer
27 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
1 vote
1 answer
87 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);...
Nathan Wilson's user avatar
1 vote
1 answer
263 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 votes
2 answers
268 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 <...
DarrenLee's user avatar
1 vote
1 answer
639 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 ...
markb's user avatar
  • 299
0 votes
1 answer
37 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 ...
user12204773's user avatar
1 vote
0 answers
34 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
2 3 4 5
11