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

learn more… | top users | synonyms

1
vote
1answer
282 views

is_home() in HTML head

Is there a way to check if the current page is the home page from within the head? My style.php needs the number of posts in the slider, but only on the home page. So I count my posts like this: ...
-2
votes
1answer
47 views

Trouble with conditional tags

I've got some code I want to run on every page other than the blog page and the archive page. If I use <?php if ( !is_home() ) { ?> The code correctly doesn't show on the blog page. If I ...
0
votes
2answers
26 views

WordPress Single Conditional for Search Page

Is there a way to filter single.php so that if someone came from search.php it would display one thing, but if they came from anywhere else it would display another? Thanks, Josh
0
votes
1answer
33 views

Conditional category & tag statement

I'm just working on a "quick" change to the blog-entry-subtitle of specific posts in a category on my wordpress website. I'm hoping to have "Published in Orchard and Vine Magazine on:" instead of ...
1
vote
1answer
310 views

Check if page/post has any anchors that link to an image jpg/gif/png

What I'm aiming to do is add fancybox to a site I'm developing, but I only want to enqueue the JS/CSS etc if the page/post needs it. My thoughts are that I would need to check all the anchor tags on ...
0
votes
2answers
51 views

Conditional css for custom post type

I'm using a wordpress theme which uses custom post types for portfolio items and "sets" to categorize them. When I hover over a "set" to edit, it reveals this at the bottom of the browser: ...
0
votes
2answers
1k views

Conditional tags issue for multiple is_page() conditions in sidebar.php

I've been pulling my hair out today trying to get this right. Basically I have a sidebar, which makes requests to individual files (such as sidebar-home.php, sidebar-residential.php) and different ...
1
vote
2answers
489 views

Conditional tag in Widget Logic for checking if top level page or if subpage

I'm using the Widget Logic plugin to show widgets on certain pages using Wordpress Conditional Tags (or any general PHP code). What I would like to do is only show a widget on child pages, not top ...
0
votes
1answer
269 views

If tag exists and equals then

I have the following code and I'm trying to check to see if a specific tag exists and if so I need it to be echo'd once. The problem I'm having is when the tag exists multiple places it gets echo'd ...
0
votes
1answer
927 views

is_search not working on search results page

Having an extra submenu with this code in sidebar: <?php if(is_404() || is_search()) : ?> <?php echo 'zou leeg moeten zijn'; ?> <?php else : ?> <?php if($post->post_parent ...
0
votes
2answers
26 views

Cannot retrieve active members only

Below is a page template where I'm trying to retrieve active members metadata (of Restrict Content Pro). Displaying users' meta is working just fine; but I can't get ONLY active members to display, ...
0
votes
0answers
40 views

Conditional tag to check if 'page.php' is being used?

I'm trying to check whether the page.php template is being used or not. I've tried is_page_template( 'page.php' ) but it doesn't work. I also can't use is_page() because I only want to do something ...
0
votes
1answer
313 views

wp_enqueue_scripts called twice?

I had some problem with WP recognizing a is_single condition for loading scripts called in function.php. I put a error_log(is_single()) to check what was going on. When opening a post page the log ...
0
votes
2answers
26 views

Is this a bad approach to add conditional comments to wp_head?

Why people say this is a bad approach to add conditional comments to wp_head? For example: function add_ie_html5_shim () { echo '<!--[if lt IE 9]>'; echo '<script ...
0
votes
0answers
20 views

Issue getting gettext to work with conditional statements

I've been trying to apply a gettext filter to return two different results for different product categories (or read as categories for posts, non-woocommerce specific). I cant seem to get it right. ...
5
votes
5answers
265 views

Actions, functions and conditionals

When developing themes and plugins it is sometimes neccesary to add some functionality to some hook using conditional statements. Example: function my_custom_function() { if( is_home()) { ...
0
votes
0answers
32 views

Identify a Woocommerce page by Wordpress conditional tags

we have a website running on WPMU, and the main site is using Woo-commerce and the sub sites doesn't use that. I use conditional statement in my meta title with following code: <title> <?php ...
0
votes
0answers
28 views

is_admin() triggers error

I've a plugin which includes other files and it looks like that : if( is_admin() ) { require( DIR. 'file.php' ); } In this file I run a class. This class is initialized on plugins_loaded. ...
0
votes
0answers
12 views

setting global and using as argument [duplicate]

I've set a global variable in functions.php like so: $cat_args = array('cat1', 'cat2', 'cat3'); and tried to use it in a template file: global $cat_args; if is_cat($args): //do stuff endif; The ...
0
votes
2answers
43 views

Check if user registered more than a month ago

How would I go about checking if current user registered more than, say, 30 days ago? I would like to display certain content only to that group of users. Thanks very much in advance for your help.
0
votes
0answers
8 views

Tag, Category and Single Conditionals

We have this sample: This function call Backgrounds in different places in the WP I add it to the <body> <?php function backgrounds(){ global $wp_query; if(is_home() || ...
1
vote
1answer
95 views

Conditional tag is_page with a custom post type

Accordingly to the is_page documentation, supplying the slug as an argument WP can tell me whether the current page is the one represented by the slug. Perhaps I am using the wrong slug? However I ...
0
votes
2answers
46 views

Entirely Different Functions.php per Page?

Is it possible via conditionals to load entirely different functions? i.e in the functions.php you have a conditional that loads in an include for the old functions, then another that loads in the ...
0
votes
1answer
29 views

Difference between is_user_logged_in and $_session['uname']

I am writing a condition to check if a user is logged in, not sure which of the below condition to use : if(!is_user_logged_in()){ And if(!isset($_SESSION['uname'])){ Basically need to ...
1
vote
0answers
28 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 ...
0
votes
0answers
22 views

Conditional within a public function within a loop

I am using a plugin to build widgets that includes images. Unfortunately it doesn't allow me to resize the images. I tried by adding a conditional but since it's in a public function and within a ...
0
votes
1answer
34 views

“if parent category is” conditional?

I searched through the codex but couldn't find anything helpful. I tried the code below but it didn't work. The default sidebar still shows up for all category pages. <?php ...
1
vote
2answers
72 views

Post.php - Conditional statements for new post and edit post

This question came up when creating a custom meta box for the edit.php page. Is there a conditional statement to target posts that are already exist vs posts that are not created yet? The idea: If ...
1
vote
2answers
87 views

Conditional tags inside a class

I have a couple of functions that I now combined in a class. The reason for that was that all these functions go towards one goal, and it is more appropriate way to use the globals between these ...
1
vote
3answers
74 views

Multiple Conditions for Child Page Title

I've been trying to work with Conditional Tags and cannot wrap my head around this problem. PHP novice here. On sub-pages I need to display the parent page title as well as the page title. I have it ...
0
votes
3answers
223 views

Is_single() conditional tag returns null in query

Trying to figure out why this won't work for me. I'm simply trying to run a loop of all posts and pages, and tag them as post and page in a array. But the is_single() conditional is not working, all ...
1
vote
2answers
33 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( ...
0
votes
1answer
47 views

Else statement not triggering after a failed if statement

I am working on a client site and the statement I wrote 6 months ago seems to have stopped working after the WordPress update to 3.8 I can't see or figure out why. There are no errors appearing it ...
2
votes
1answer
80 views

Make specific tag visible only to logged in users in front-end

I have this specific tag I need to assign to my posts but I need to hide it from regular visitors so that only logged in people can see it. How do I go about it? What WordPress function/hook should I ...
0
votes
2answers
176 views

WP_Query and is_page_template() conditional

I have a custom query that goes looks like this: $temp = $wp_query; $wp_query = null; $args = array('posts_per_page' => 5, 'post_type' => 'gallery', 'post_status' => ...
0
votes
1answer
49 views

Conditionals in WP_Query

What I'm trying to do is this: If in the last 7 days someone has added a post in the category 'featured' display it in the loop. Otherwise, display the most commented post from the last seven days. ...
-1
votes
3answers
2k views

alt attributes not showing on pages

I have downloaded a wordpress theme called livepuse, and unfortunately the alt tags are not showing on portfolio pages for my images. The website is as follows: ...
0
votes
2answers
36 views

Try to run a function only on Home

I'm trying to run disable auto p filter on only my home page. In my functions.php file, I added this snippet: function removeP(){ if ( is_page( 4 ) ) { remove_filter('the_content', ...
0
votes
1answer
40 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" ...
-2
votes
1answer
183 views

if (is_page(**PAGE ID**)) not working

I'm following this tutorial on adding Google Content Experiments code to header.php. I added the following code to header.php: <?php if (is_page('346') ):?> <!-- Google Analytics ...
0
votes
1answer
175 views

is_singular() not working if called via callback function of admin-ajax.php

In my single.php I've some code like this ... if(is_singular('post')) { echo 'Blog'; } else { echo 'CPT'; } If I approach single.php from blog or CPT index page by using the_permalink(), ...
1
vote
1answer
51 views

Hide a template part when page is password protected?

I'd like to hide the sidebar of my page when the page is password protected and the password has not yet been entered. I've searched for a while and haven't found any condition I could use. Maybe ...
0
votes
2answers
257 views

How to use Wordpress Conditional Tags in get_posts foreach loop

I have a page which has a jquery tab function to output the list of pages that are the children of this page (Bio, Archives, Contact). However I am trying to make a conditional in the foreach loop ...
1
vote
1answer
3k views

How to insert widget areas specific to certain pages (or posts, etc.)?

I am developing a theme the pages of which (as well as posts) are so different from the home page that I want different widgets on their sidebars.Is there a way to do it? I'm calling the sidebar on ...
1
vote
1answer
135 views

Filter out some plugin action in wp head / wp_footer

I am using a plugin called "syntaxhighlighter". I know not to ask for plugin specific questions but rather how to filter out action added to the wp_head / wp_footer conditionally... This is a ...
0
votes
1answer
69 views

Help with if else statement for separating content from image attachment

I am currently having some trouble executing the following. I would like to separate the image (wp_get_attachment_image) from the content (get_the_content) by using a conditional statement to display ...
0
votes
3answers
160 views

Conditional Statements

I have created Custom Post Type called - listing Also created custom taxonomy - listingcategories In listing categories, i have created two categories music 2. features Now i want to create a ...
0
votes
1answer
55 views

Need a conditional to test if title of parent page matches title of child page

In my main loop, I need to incorporate proper html markup into a conditional to test if title of parent page matches title of child page and do (or do not) display certain content. Default might be ...
0
votes
0answers
42 views

conditionally display text - on nextGEN gallery pages only

I'd like to use functions.php to display some text via a hook on pages displaying a nextGEN gallery. I can't find any documentation for nextGEN code. something like: // add note to nextgen gallery ...
20
votes
6answers
55k views

If is custom post type

I am looking for a way to test if a post is a custom post type. For example, in say the sidebar I can put code like this: if( is_single()) { //code here } I want code were I could do ...