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

learn more… | top users | synonyms

26
votes
6answers
68k 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 ...
13
votes
2answers
6k views

Check if we're on the wp-login page?

How can I check if the current page is wp-login.php or wp-signup.php ? Are there more elegant solutions than using $_SERVER['REQUEST_URI'] ?
9
votes
2answers
3k views

Toggle admin metabox based upon chosen page template

I'd like to have a custom field interface show up only when a certain template is assigned to a particular WordPress page. Any ideas?
7
votes
5answers
304 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()) { ...
6
votes
1answer
3k views

How to determine whether we are in add New page/post/CPT or in edit page/post/CPT in wordpress admin?

This seems like simple thing but I need way to determine whether the current screen is for Add New or Edit ( a sort of wordpress admin conditional tag). Is there a built in function for this already, ...
5
votes
2answers
165 views

How to force a query conditional?

There is a long-standing WordPress core bug (#16373) in which, if custom query variables are registered and present in the query string, the query will not set is_front_page() true, even if 'page' == ...
5
votes
4answers
1k views

How to make plugin required in a wp theme without using php conditional statements when calling an individual function from that plugin?

One of my Wordpress themes requires a few third party plugins to run correctly. Most of the times I used to call functions from third party plugins using conditional statements like ...
4
votes
3answers
222 views

the_content and is_main_query

I am filtering the content with the the_content filter. Everything works perfect, excerpt that my changes are applied to custom queries as well. My changes appear in the sidebar as well if the widget ...
3
votes
1answer
2k views

how to check if front page is set to show a static page

I need to determine whether the reading settings are set to use a static page or the latest post for the front page. Is there a conditional that will return true if the front page is set to show a ...
3
votes
1answer
103 views

Possible to use conditionals within add_feed() callback?

I'm using add_feed() to create some custom feeds but calls to is_singular(), is_home() etc... just don't seem to work within the callback. Is there a workaround for this? Example code: add_action( ...
2
votes
1answer
4k views

Conditional for single-{post-type}.php

Please help with this code for custom post type "video": If is single-video.php page { list custom-taxonomy of video. Example actors } Else { do nothing } I´m tried with is_single, ...
2
votes
1answer
1k views

Problem using is_single() to enqueue script from functions.php

I'm having trouble only adding scripts to single post pages. I need to both include and exclude certain scripts using is_single() but it doesn't work either way I try it. I have the template tag on ...
2
votes
1answer
102 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 ...
2
votes
1answer
38 views

How can i know when i can execute what functions of wordpress?

I like to do a bunch of stuff only on homepage and archive pages i am working with the genesis framework (not really matters i guess) if( is_singular() ) { wp_die('functions.php'); } ...
2
votes
4answers
424 views

Conditional check for front-end which includes ajax

I need a conditional which exits if the context is not a front-end view including AJAX requests. I have this at the moment: if (is_admin() && !DOING_AJAX) return; The DOING_AJAX bit ...
2
votes
1answer
365 views

Problem with “conditional tag”: if empty

I've been trying for a while now to make it so that there is nothing shown if there are no Related Posts. Currently the headline and the container (of course empty) are displayed. Like I said I tried ...
2
votes
2answers
2k views

How To Remove The Author(s) From Certain Posts

There are certain posts on the website I'm developing, that don't need the author(s) by-line. (such as press releases) Is there any method, that allows me to remove the author (and co-authors) for ...
2
votes
1answer
34 views

Conditional tag search-no-results

Is there a way to make a conditional tag that tests if it is search-no-results page? I know that there is a function to check if is_search() page: if(is_search()){ echo "search page"; } But I ...
2
votes
1answer
321 views

Bulk add tag (or any sort of label) to posts who have custom excerpt

The situation is the following: The blog as of now has 2200+ posts. In the beginning (2007/2008) I was using manual excerpts where I would put an image and a little bit of text. The manual excerpt ...
2
votes
1answer
383 views

Closest thing to an is_widget() tag?

I have a custom widget with a WP_Query loop that's using get_template_part() to include some standard information that I also use in theme files. However, I need to make one small change to the ...
2
votes
1answer
339 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 ...
2
votes
1answer
501 views

Conditional based on the User Role of the Current Profile the user is viewing - BuddyPress [closed]

I'm using BuddyPress and need a certain block of code to show up on user role Store Owner profiles only. I'll be putting it in member_header.php, so it's just a template file. I've been digging for a ...
2
votes
1answer
362 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
138 views

Featured Image Size Conditional Tag?

Is it possible to check what image size has been selected for the featured image and only display that image.. For example. <?php if(has_post_thumbnail('small-image')): ?> ...
1
vote
2answers
148 views

How can I link a CSS file only on single posts?

If I understand is_single() correctly, it's only supposed to return true when the current "post" (in a generic sense) is a literal post (i.e., it has a post_type of post), and that it will return ...
1
vote
2answers
201 views

Output 2 items within the Loop

I have a query that loops through <li>'s and displays the number of <li>'s I have. Is there a way I can make the loop pull 2 <li>'s at a time rather than one? // 5 list items ...
1
vote
1answer
458 views

Using Conditional Statement in functions.php

I've got this code below in my functions.php and I'd like to add two filters with conditional statement not to effect every query_posts. Something like this if(!is_admin() && ...
1
vote
1answer
119 views

WordPress conditionals not working

Hi I am building a jquery accordion which works fine on my site. However I am now trying to introduce conditionals to only enable it on posts and pages, however it doesn't work, it seems the ...
1
vote
1answer
332 views

What is the condition to check if we are in admin or frontend?

What is the condition to check if we are in admin or frontend? I want to add_action not in backend, but only in frontend.
1
vote
2answers
87 views

Same Conditionals Not Working on Two Different Hooks

Everyone! I am new to WP and trying to build a plugin. I have the following codes working properly: add_filter('the_content', 'say_hello'); function say_hello($content){ if(is_single() || ...
1
vote
3answers
753 views

Is there a way to check which template file is being loaded, if it is not a page template file?

I don't see any way of testing which template file is being loaded, if the template file is not a page template. Otherwise I would use is_page_template(). For instance, I am using a home.php template ...
1
vote
2answers
135 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
1answer
376 views

is_page not working when loading javascript with add_action in functions.php

This code is working in my functions.php and it's loaded properly: add_action('wp_enqueue_scripts', 'js_custom', 50); function js_custom() { wp_register_script( 'js_custom', ...
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
273 views

Checking whether template part is loaded in a page

I have a template part like this: <nav id="subpagemenu" class="sidebar"> <?php get_template_part( 'nav', 'subset' ); ?> <?php get_sidebar(); ?> </nav> Both of these ...
1
vote
1answer
430 views

Way to check if we are in Theme Customizer mode? [duplicate]

Possible Duplicate: How to execute conditional script when on new customize.php (Theme Customize) screen Is there a Conditional Tag, or any other method, that we can use to check if we are ...
1
vote
1answer
3k views

If on term-page -> get the current term?

I'm trying to write a kind of "breadcrumb" function in my "functions.php" I'd like to query if I'm on a term-page and if so I want to print the current term I'm in. By "term-page" I mean the ...
1
vote
2answers
229 views

Change Site Title and Description html tags if not home page

For the purpose of good HTML structure, accessibility and SEO I'd like to change the site's title and description from H1 and H2 to P when appearing on any page other than the homepage. A conditional ...
1
vote
1answer
370 views

is_page() conditional not working inside an AJAX function

I have a jQuery ui tabs that load posts via ajax on sidebar. Now in a specific page i want to filter the query post via is_page(); conditional. But in my case its not working. function ...
1
vote
1answer
749 views

functions.php conditional tag - only show in single.php?

//Geo Map add_action( 'woo_post_inside_after', 'my_geo_mashup' ); function my_geo_mashup() { global $post; if ( in_category('listings') ) { echo GeoMashup::map(); } } Works to ...
1
vote
1answer
91 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 ...
1
vote
1answer
278 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 ...
1
vote
2answers
146 views

is_archive() doesn't work on public query var archive pages?

Public query vars are those available and usable via a direct URL query. E.g. example.net/?category_name=tech&tag=gadgets But doesn't example.net/?category_name=tech&tag=gadgets show ...
1
vote
1answer
100 views

custom comments on specific post type

I have a custom post type called debate and I want to create some custom fields just on this post type. So, I have this code: function debate_comment_fields( $fields ) { if( is_singular( ...
1
vote
1answer
413 views

How to use is_feed() to target a category feed?

is_feed (one of the many conditional tags) can be used to determine if the current query is for a feed. But how do I use it to target all category feeds? (or tag or custom taxonomy feeds for that ...
1
vote
1answer
534 views

Wordpress function like is_category for subcategory? is_subcategory?

Is there a function in WordPress that will check if the page you are on is a sub-category archive page? Like the way is_category checks if it's a category page?
1
vote
1answer
672 views

How can I achieve something like has_post_format( 'standard' )?

In opposite to get_post_format, the conditional has_post_format() function returns a boolean value and should be the perfect function for a conditional check like: if ( has_post_format( array( ...
1
vote
1answer
205 views

Check if post has gallery images/media

Is there a Wordpress conditional that I can use to check for gallery images/media in a post? I do not want to check if the [gallery] shortcode exist in a post. Attached is a screenshot of what I ...
1
vote
3answers
535 views

Check if home.php and set home.php as page_on_front

I want to include a custom inline js on home page only. I havent set home page from reading section. I am using home.php file. function print_my_inline_script() { if (is_home() && ...
1
vote
1answer
111 views

Unexpected results with conditionals inside template part

Scenario: I have a template part loop-product.php which i am calling from home.php, taxonomy.php and a page template template-products.php. Inside that template part loop-product.php file i am setting ...