Questions tagged [conditional-tags]

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

75 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
2
votes
0answers
636 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 ...
1
vote
0answers
30 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 ...
1
vote
1answer
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 ...
1
vote
1answer
119 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
vote
0answers
21 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 ...
1
vote
0answers
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 ...
1
vote
0answers
648 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 ...
1
vote
3answers
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 ...
1
vote
0answers
737 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 ...
1
vote
1answer
157 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()...
1
vote
0answers
118 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 ...
1
vote
3answers
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 ...
1
vote
0answers
528 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 ...
1
vote
0answers
125 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 ...
1
vote
2answers
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-&...
1
vote
1answer
478 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....
1
vote
0answers
346 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 ...
0
votes
0answers
32 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 ...
0
votes
0answers
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 = ...
0
votes
0answers
23 views

Conditional widget for a listing archive page

I am building a listing website (using ListingPro theme) Inside the Listing Archive page I added some advertising widgets and I need to add conditions to it so that different content is displayed ...
0
votes
1answer
33 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&...
0
votes
0answers
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 ...
0
votes
1answer
110 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(), ...
0
votes
1answer
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 ...
0
votes
1answer
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 ...
0
votes
1answer
79 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
72 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
1answer
59 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 ...
0
votes
0answers
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 ...
0
votes
0answers
59 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 ...
0
votes
1answer
129 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" ...
0
votes
0answers
421 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
0answers
207 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 ...
0
votes
0answers
67 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 (...
0
votes
1answer
334 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 ...
0
votes
0answers
29 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 ...
0
votes
0answers
384 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 ) ) . '">' ...
0
votes
1answer
218 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&...
0
votes
1answer
922 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 ...
0
votes
1answer
434 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,...
0
votes
1answer
65 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; ...
0
votes
2answers
34 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=\"...
0
votes
0answers
98 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 ...
0
votes
0answers
267 views

How to detect if bbPress forum index

I posted a question in bbforum 2 months ago without success, https://bbpress.org/forums/topic/enque-bbpress-scripts-only-on-forum-pages/ I am working on a theme and need to deque all bbpress scripts ...
0
votes
1answer
58 views

if is specific custom post in cpt

I need to be able to target a specific post in a CPT. According to the codex I can use the following code to reference a specific custom post type; `if( is_singular ('cpt-name') { //Something here ...
0
votes
1answer
58 views

Conditional tags returning different results for different areas on a page?

I have a custom template. I want to output some JavaScript based on the type of page I am on. My current setup includes a static front page, with a template assigned it to it. This template is also a ...
0
votes
1answer
132 views

From my Plugin Settings Page use check boxes to load specific css files (e.g. Bootstrap / Foundation)

This is my first post on here so bare with me if something goes terribly wrong. The wp plugin I am building requires bootstrap for the shortcodes it generates to be styled as expected when rendered ...
0
votes
1answer
36 views

Image to only show up in the single post page, not on the blog/home page

I'm new to WP, and I'm working on a custom theme. Images in posts show up not just on the single post page, but on the blog/home page too(where the recent posts are listed). I want them to only show ...
0
votes
0answers
59 views

WordPress Conditionals Giving Me A Headache

I have a WordPress Foundation theme I have developed called WP-Forge. Here is the link if you would like to look so you can get a general idea of what I am talking about. I have received a lot of ...
0
votes
2answers
288 views

if statement for featured images

I'm just looking to make sure my home page and pages display my featured image if set, and other wise if not set show blog-banner.jpg. So that's what I thought I had however now my 404 error page ...