The conditional-content tag has no wiki summary.
12
votes
5answers
23k 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 ...
7
votes
3answers
5k views
Loading scripts only if a particular shortcode or widget is present
I needed a way to filter a page/posts content before it was loaded so I could add scripts to the header if a specific shortcode was present. After much searching I came across this on ...
5
votes
3answers
649 views
Check if first paragraph is an image, then show custom code right after it?
I would like to add some code in functions.php that does this:
If the first paragraph contains an image, show my custom code right AFTER it. For example:
<div class="entry-content">
...
4
votes
6answers
3k views
wp_enqueue_script adding conditional statement not working
This is the code im using in my functions file:
add_action('init', 'sort_out_jquery_pngfix_frontend');
function sort_out_jquery_pngfix_frontend() {
global $wp_scripts;
if(!is_admin()) {
...
4
votes
1answer
3k views
how to create a conditional content_width for a wordpress theme?
I'm trying to create a conditional statement for the content width in the functions.php of my theme. So some categories will have a content_width of 580, some will have 900. This will make the oEmbed ...
3
votes
3answers
83 views
How do I place content on archive pages but not on main page?
I would like to place content in a sidebar of my blog articles when they are viewed in the archive, but not show this content when the blog articles are shown on the main page of my site.
Can this ...
3
votes
2answers
775 views
How to display the_post_thumbnail if a post has one or otherwise display the first image in a post?
I would like to create a condition that checks to see if a post has a thumbail and if it does display it, otherwise display the first image in a post.
I tried something like this in my loop.php but ...
3
votes
1answer
608 views
Loading Javascript Only When Specific Content Existing in a Post?
I'm trying to add Javascript for my "PrettyPhoto" plugin to pages only when their content contains rel='prettyPhoto'. This looks very simple to me but all solutions I've found on the internet doesn't ...
3
votes
2answers
399 views
how to test for attached image
I am trying to find out whether or not a post has images. If it does, I then want to know if a featured image was specified for the thumbnail - if not, the get_thumb() function will assign an image ...
3
votes
2answers
442 views
Display only certain posts based on visitor's country?
Is it theoretically possible to have the following feature?
Each post has a country code. When a visitor comes in, the system will determine the visitor's country code. Then when the page renders, ...
2
votes
1answer
2k views
How can I determine if a post has an image attachment?
As far as I know, there's not a simple function that will return true if a post has an attachment. With that in mind, what's the best way to determine if a post has an attachment (or even better, has ...
2
votes
7answers
5k views
Display navigation menu item conditionally based on user capabilities
I have one "branch" of my main site's navigation tree that should only be accessible to a set of registered, logged-in users. I understand how to query a user's role and capabilities. This question is ...
2
votes
1answer
1k views
Checking if a Page has an Associated Term?
I am looking for a way to do some conditional logic on terms associated with a post.
Essentially I created my own custom taxonomy for "age groups" and have created three terms for them. Kids, Teens, ...
2
votes
1answer
515 views
How to make gravatar.com avatars conditional?
Problem: I am using custom avatars for registered users and my own locally-hosted image as the default gravatar. I want to stop WordPress making HTTP requests to check for gravatar.com images on every ...
2
votes
1answer
126 views
Conditional Ajax inclusion
I have a custom interface that uses 30+ ajax files while running...
some files are only used in category.php while othere's are only
used in page.php...
i include the ajax loader php files in my ...
2
votes
1answer
559 views
If function exists, and array is met, echo function?
I have a function like the following:
<?php echo my_custom_function( array( 'category_url'=>'My Special Category' ) ); ?>
It pulls data from the "My Special Category" and displays it. I ...
2
votes
1answer
69 views
Performance-wise, is it better to enqueue a (small) script on every page or test to see if it's needed?
I'm using the FitVids.js script to make YouTube video embeds work with a responsive layout. The script is < 3kb, but only about half of my pages actually have YouTube embeds.
In terms of total ...
2
votes
1answer
295 views
Custom Menus, Widgets & Conditional Statements
I'm employing custom widgets for my client because it's easy and they have several menus they need to create specific to site sections. I then want to allow them to add to the custom menu dynamically ...
2
votes
1answer
510 views
Conditional tag affecting taxonomy term and its children?
I am wondering how can I write a conditional tag that affects a custom taxonomy slug and its children?
Found this in Wordpress Codex:
is_tax( 'flavor', 'mild')
When the archive page for the ...
2
votes
2answers
1k views
Loading Scripts on Specific Pages
In child theme I created a functions.php file that loads scripts and style files, the code is below.
The section that loads libraries and scripts to all pages other than admin, in other words the ...
2
votes
1answer
110 views
Search result conditonal tag
Is there a conditional tag (or a similar concept) that can tell me wether the search returned posts or not?
1
vote
3answers
177 views
A function like is_page() but returns true if on any sub page of given page
In my header I use this code:
if(is_page("stores")) {
// Do something
}
I run some code if on the page stores but what I want to do is run that code if the page is stores or any page that is a ...
1
vote
2answers
161 views
Conditionally load CSS/JS/PHP in wp-admin if using a mobile device
I'm looking for a way to conditionally load different scripts if the user is accessing the admin area from a mobile device.
In my case I'm looking to restrict the user to just be able to make new ...
1
vote
1answer
521 views
Need help on creating If-statement for custom meta fields
I'm using Wordpress. I have a movie review website called Filmblurb. For my blog posts, I'm trying to create posts with different categories. Under the "Reviews" category, I have a "Details" box that ...
1
vote
3answers
723 views
How to show my sidebar in specific page only?
I would like to show a plugin in a specific page's sidebar only.
For Example:
I have the pages like ..
home
about us
sub page 1
sub page 2
sub page 3
sub page 4
UPdate:
i want to show, ...
1
vote
2answers
641 views
Function like in_category for custom taxonomies
I'm trying to display different content depending on the taxonomy that was been selected. For example I have a taxonomy named Type. Inside that taxonomy I have several different children, one is ...
1
vote
2answers
631 views
How to tell if the user is an admin?
I need to show some info only to admins visiting a page, so I need a conditional tag to identify them. So far I have found:
<?php if ( current_user_can('manage_options') ): ?>
is this the ...
1
vote
1answer
93 views
Conditional Statement - Best Way to Remove Nav on Contact Page
I was thinking of removing navigation on my contact page.
I was thinking of inserting a conditional statement and an inline CSS style to "display: none;" if the page template was the contact page.
...
1
vote
2answers
116 views
can't use the page_test method to check pagination
I've tried to follow the example for Testing for paginated Pages but i don't know why it isn't working. i put it in the single.php file for post detection. i don't know why the page_test is broken. ...
1
vote
1answer
47 views
Check to see if specific loop has less than certain amount of posts
I'm looking for a way to check how many posts are returned by a specific loop. So if I have a loop like this..
<?php
$featured_post_id = get_the_ID();
global $post;
$args = array('cat' => ...
1
vote
1answer
317 views
how to know if the post has pagination (<!--nextpage-->) or not
i need a solid solution for checking if a post has pagination or not, regardless of the number of current page in the pagination, and even if the post is in the first page of the pagination.
the check ...
1
vote
1answer
508 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
3answers
583 views
How to Add Javascript Only When a Function Exists?
I have a few function. For both of them need javascript code. I need to add javascript code in header only when function is active. At this time I have all my javascript code in header for all my ...
1
vote
1answer
21 views
Add user settings to specific roles
Is it possible to do this? I already know about get current_user_can(), which does not work like I need. I'd like to be able to use an array if there are multiple roles.
// Check roles to only add ...
1
vote
1answer
168 views
How do display simple page for printing product info?
I'm using WP 3.1.2 and latest e-commerce plugin. Now I'm stuck at creating simple page for printing product info. It has to be only product information with not WordPress header and footer. The pop up ...
1
vote
2answers
311 views
Conditional custom field query
I'm working on a job board-type site, and the client want to sell featured posts. They want the featured posts to expire from showing up in the "featured" section after a predetermined period of time, ...
1
vote
1answer
994 views
Create a new usermeta field for users
How do I create a new usermeta field with a drop down selection values?
Im want to create a conditional statement for all users with a certain value of the new custom field I want.
For example,
The ...
1
vote
2answers
410 views
wordpress is_page() problem
I want to load a .js file only on a specific page in Wordpress 3.1.2
So I use in functions.php
function my_init_method() {
if (is_page('myinfopage')){
echo "yeeessssssss";
...
1
vote
1answer
551 views
Can I create a loop with multiple post types and specify different $args for each post type?
I'd like to create a custom loop that includes all Post types: Post and Video. Then I'd like to specify to show all posts of the post type Video, but only show posts that are in the category ...
1
vote
1answer
439 views
Conditional PNG Overlay in Custom Post Type Loop Depending on Post Type
I have a loop pulling in two different custom post types. I have that loop showing the thumbnails of posts. Each post type used to have its own seperate loop and I had set up some png overlays to ...
1
vote
1answer
53 views
How to not show post_thumbnail from specific category for not logged users
Can you guys help me with some examples so i can sort out the thumb posts from a specific category (EXAMPLE) to not be shown for not logged users, instead to be shown an image which tells them that ...
1
vote
2answers
74 views
Displaying a widget in sidebar only when no other widgets rendered?
I am working on a custom theme, basically migrating a current sites look and feel into WordPress. Most of everything is based on Pages, and all of these pages should have a left sidebar. Of those ...
1
vote
2answers
178 views
Reordering Buddy Press profile navigation
I am using this code to reorder the positions of the menu items for BuddyPress profile. I am using the xprofile (not sure if that makes a difference). Here is the code that I am trying to use:
...
1
vote
2answers
79 views
Determine page content based on page parent
How can I display a gallery shortcode for pages who are children of the page with an ID of 9, and the regular content for pages who aren't? This is what I've tried so far, but it's not working:
...
1
vote
5answers
177 views
meta content on required pages
I need to post extra information on programs pages, so i have decided to use wordpress metabox but its showing on all pages. So is there any condition check so it could put meta box on those sub pages ...
1
vote
2answers
242 views
Plugin Code ONLY on Post Edit Page
I have a wordpress plugin that is interfering with the function of another plugin. But, I believe the interference only occurs on the admin side.
I've found the lines within the code that are ...
1
vote
2answers
821 views
is_front_page, is_page('slug'), is_page(id) not working
None of the following are working to display conditional format in the sidebar when the current page is the home page:
is_front_page,
is_page('home'),
is_page(id)
I added an else clause which is ...
1
vote
1answer
199 views
Conditional Shortcode image display
Got a problem with a shortcode.. i probebly dont know where & how to set the condition so it will display the right image according to the topic / category of the toturial..
Help Plz :)
function ...
1
vote
2answers
273 views
Conditional display for custom fields/taxonomy
If there's a value for the custom field, I want it to display the value. If there's no value for the custom field, I want it to display "N/A". I have this working for custom fields but cant replicate ...
1
vote
1answer
460 views
Can shortcodes contain conditional statements? Even without them my shortcode renders blank page
The following code is supposed to allow for a shortcode that includes many attributes, but not all of the attributes may always be present in which case I do not want the containing element to show ...