2022 Developer Survey is open! Take survey.

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
1 answer
26 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 :
user avatar
  • 1
0 votes
1 answer
17 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-...
user avatar
1 vote
1 answer
49 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']-&...
user avatar
1 vote
1 answer
30 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( '...
user avatar
  • 111
0 votes
0 answers
45 views

Automatically insert H2 on h2 tags on WordPress post

I have just migrated my websites from HTML to WordPress version. I have saved all my Posts on a txt file. Now after I imported to WordPress all the HTML (h2 and h3 ) tags inside the contents of the ...
user avatar
0 votes
1 answer
28 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 ...
user avatar
1 vote
0 answers
33 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 ...
user avatar
0 votes
0 answers
17 views

Check if is Post or Comment

I made a function to display the time since posting an article or comment. function custom_posted_ago() { global $post; global $comment; if ( get_post_type() ) : $object_ID = ...
user avatar
  • 5
0 votes
1 answer
72 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() ) { $...
user avatar
  • 11
1 vote
1 answer
52 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 ...
user avatar
0 votes
1 answer
267 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 ...
user avatar
  • 15
0 votes
1 answer
41 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, '...
user avatar
  • 3
0 votes
1 answer
2k 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 ...
user avatar
0 votes
1 answer
94 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&...
user avatar
  • 175
0 votes
1 answer
60 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 ...
user avatar
0 votes
1 answer
381 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 ...
user avatar
2 votes
1 answer
141 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 ...
user avatar
  • 21
1 vote
0 answers
34 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 ...
user avatar
  • 31
0 votes
1 answer
239 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-...
user avatar
0 votes
0 answers
30 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 ...
user avatar
  • 111
1 vote
1 answer
1k 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 ...
user avatar
0 votes
1 answer
23 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 ...
user avatar
0 votes
1 answer
143 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(), ...
user avatar
  • 1,913
0 votes
1 answer
38 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 ...
user avatar
1 vote
2 answers
41 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('...
user avatar
0 votes
1 answer
78 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 ...
user avatar
0 votes
1 answer
196 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 ...
user avatar
  • 1
0 votes
1 answer
224 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 ...
user avatar
  • 838
0 votes
1 answer
686 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 ...
user avatar
1 vote
1 answer
2k 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 ...
user avatar
0 votes
1 answer
25 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 ...
user avatar
1 vote
1 answer
62 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);...
user avatar
1 vote
1 answer
148 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 ...
user avatar
-1 votes
2 answers
241 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 <...
user avatar
1 vote
1 answer
343 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 ...
user avatar
  • 279
0 votes
1 answer
35 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 ...
user avatar
1 vote
0 answers
26 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 ...
user avatar
  • 123
0 votes
1 answer
334 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) ...
user avatar
  • 3
0 votes
2 answers
1k 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....
user avatar
  • 107
0 votes
1 answer
87 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 $...
user avatar
  • 13
0 votes
1 answer
50 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, ...
user avatar
  • 25
0 votes
2 answers
959 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 ...
user avatar
0 votes
2 answers
179 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> ....
user avatar
0 votes
1 answer
79 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 = [...
user avatar
  • 101
0 votes
1 answer
3k 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-...
user avatar
0 votes
1 answer
73 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 ...
user avatar
1 vote
1 answer
500 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')) { ...
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 ...
user avatar
  • 127
0 votes
1 answer
131 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()...
user avatar
0 votes
2 answers
45 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 /** * ...
user avatar
  • 15

1
2 3 4 5
10