Questions tagged [conditional-content]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
1k views

Conditionally remove comments and post meta in functions.php

I'm new to Wordpress and am coming from the point and click world of Joomla! what was easy there now involves some solid php knowledge to replicate in Wordpress ;) I'm try to conditionally remove ...
  • 253
0 votes
1 answer
1k views

Is there a way to password-protect part of a post?

Is there a way to have a page displayed to the public, but have an extra custom field that doesn't display unless a password is entered? I suppose I could do entirely manually without WordPress ...
0 votes
1 answer
497 views

How to get type of archive whether it is post or date or category archive?

using function is_archive() we can know whether it is archive page or not. But if it is archive page how can i find whether it is author archive page or category archive or date archive. I have ...
  • 2,523
1 vote
1 answer
168 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 ...
0 votes
1 answer
1k views

How to hide <pre> and <table> content from auto-generated excerpts?

Auto-generated excerpts just take the first x characters from the post content and cut that off at a certain point. When there is a table or pre element in that part, the excerpt looks rather useless ...
  • 106k
1 vote
1 answer
2k views

How to display conditional-content if wp_nav_menu( $args ) retruns something

I have a sidebar that displays child links of the current page (using this solotuin by https://wordpress.stackexchange.com/a/2809/27414) which works perfectly. If there is child links to be displayed ...
  • 163
0 votes
2 answers
52 views

Checking conditionals

We all know about the default WordPress post types, these being aside, gallery, status, chat and so on. any good theme should support all of them. In the case where a theme does support all of them, ...
  • 1,055
1 vote
1 answer
93 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 ...
-2 votes
2 answers
115 views

How to set up a echo? [closed]

My problem is that i don't know how to set up a echo I think. I need it to just wrap a if statement correctly around the code below Please Help...Thanks SO much <?php global $post; if(...
0 votes
1 answer
6k views

Add class to DIV depending on page loaded

I'm designing a new theme and in my page template a have a section where an image is displayed . I would like this image to change depending on which page is loaded. The section is a DIV like this: &...
  • 336
0 votes
1 answer
660 views

Custom Meta Box If Else Statement

I have created a custom meta box for posts and I need to display said data. I have been using the below method to display the data, But I am in need of a slightly different solution. <a href="<?...
  • 127
0 votes
2 answers
860 views

Subpage Conditional

I am looking for a way to write a condition for a subpage...in other words if we're on the subpage "duck" then do something...if not do something else. I found some code I thought would work, but it ...
  • 1,133
0 votes
1 answer
210 views

Parse a shortcode differently based on on what it's nested in

Suppose we have two different sets of nested shortcodes, like this: Apple version [wrapper snack="apple"] Today I had a [flavor] snack... [/wrapper] Desired output: My snack was quite HEALTHY today.....
  • 2,926
1 vote
3 answers
514 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 ...
  • 225
0 votes
1 answer
177 views

NextGEN Conditional Statement [closed]

What I'd like to do is if the NextGEN gallery has more than one page (pagination) execute some code...I got close: <?php $nggpage = get_query_var('nggpage'); if ($nggpage > 1) { ...
  • 1,133
0 votes
1 answer
845 views

Help with this custom field conditional if no field is set display nothing

I'm using the code below to display an image if the swap_select custom field value is true. If it's no it displays nothing. However when posts are first created no custom field exists. So what would ...
  • 953
0 votes
2 answers
558 views

exclude custom post type from running a function

I have the following code in my functions.php file to display post shortlink in my posts (I prefer not to edit theme files if possible)... function add_post_content($content) { if ( is_single() ) ...
0 votes
1 answer
844 views

Only on single post page

I am using this code to show ad below single post but only if it is in specified category. Code is giving right out put but it is also showing up on archive pages. I just want to show on single post ...
  • 167
0 votes
1 answer
295 views

Conditional function for excluding first image from content, not working

I have the following function: function remove_images( $content ) { if( ( is_category() || is_archive() || is_home() ) && has_term( 'MyCat', 'category', $postID ) ) { $postOutput =...
  • 191
2 votes
1 answer
162 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 ...
0 votes
1 answer
27 views

why is my custom loop failing?

I have a custom post type to get images. I am setting up my theme to display a specific way when it is first installed. For some reason, my code is stopping the bottom half of my page from displaying. ...
  • 1,353
-2 votes
1 answer
1k views

Weird html output of single_cat_title - is not inside of the html element?

I'm displaying a single "featured" post at the top of the blog index page, and category pages. I'm using this conditional to display the category name of the category page if it is a category page, ...
0 votes
2 answers
155 views

Check IF single OR multiple custom data has been entered

I'm building a single template right now for a custom post type. I'm wondering if there is a way to check if either at least one or multiple of the custom values has been entered so I can display the ...
0 votes
3 answers
155 views

How do I add a nested conditional within an echo - to use a default image if there isn't one in the post?

I'm trying to add a conditional that will display a default image if the "image" field isn't populated... here's what I'm trying to work with: $args = array( 'posts_per_page' => 3, '...
3 votes
4 answers
14k views

Show content after the first and second paragraph

The function below is used to show certain content after the first paragraph. I would like to show 'content X' after the 1st paragraph and 'content Y' after 2nd paragraph. <?php $paragraphAfter= 1;...
  • 317
1 vote
2 answers
600 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,251
0 votes
1 answer
3k views

Conditional for a Single Post That Belongs to a Category?

I have categories like gaming and movies on my website and when a user visits any of these categories the content in the sidebar is displayed depending on the category they are in. So gaming content ...
  • 729
1 vote
2 answers
1k views

Reordering Buddy Press profile navigation [closed]

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: <?...
  • 822
1 vote
1 answer
892 views

Exclude custom function content from certain pages

I have added a small custom function to display a little author bio blurb at the bottom of each blog entry in my functions.php file inside the current theme that I am using. So far so good, it is ...
  • 113
2 votes
1 answer
776 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,772
0 votes
2 answers
133 views

How to use "Cases" instead of "IFs" for conditional logic

Recently I've been developing sites for WordPress that are both increasingly complex but also have much higher rates of traffic. I remember when I was learning the ropes from another about PHP, that ...
  • 177
0 votes
1 answer
571 views

Limit page template choice by page title or ID?

I'm developing a multisite and creating my own themes for it. All the themes will feature some standard pre-defined pages eg. homepage, about, blog, contact us etc. Each page will also have a number ...
1 vote
1 answer
4k views

Change a url / link if a user is logged in?

I'm working on some themes for a multisite and would like to modify the code below. It relates to a special div that will display an image or logo that users upload. Normally the logo links to the ...
1 vote
2 answers
2k views

Add default content to posts in a specific category?

Update / Question clarification: How could you modify the following code from this thread: Force category choice before creating new post? which offers a drop-down menu to choose a category BEFORE ...
0 votes
1 answer
428 views

Why is the `if else` not working?

I have this on my header.php. It checks whether the page is on homepage/frontpage, is on category/children of/has the category of "gamenews", or is on category/children of/has the category of "...
  • 506
0 votes
1 answer
64 views

include <p> content within conditional statement?

I have a gallery page wherein there are multiple individual galleries/sub-pages. I handle this function by using- <?php if( is_page( 39 ) ) { echo do_shortcode('[nggallery id=1]'); ...
0 votes
1 answer
41 views

Specific coditional usage [closed]

I have some trouble making work a conditional inside a Function. check this out: I'm using this function: function get_spec_1(){ $desc1 = get_post_meta( get_the_ID(), 'eco_mb_tp_1', true!= "" ); ...
  • 17
34 votes
8 answers
69k views

wp enqueue style on specific page templates

I am in the process of a theme, I would like to add landing pages using page-templates. I cannot find anywhere that shows how to enqueue style or js for specific page templates. Any suggestions. Ex. ...
  • 441
1 vote
2 answers
134 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: <?...
0 votes
2 answers
71 views

Looks like this if condition is not working [closed]

I want a query to be executed IF the following condition is true... but looks like the query is executed anyways. if($post->post_parent = '302'){ // Query goes here } Is this query fine?? I want ...
  • 293
0 votes
1 answer
1k views

If else with shortcodes

I only want one of these shortcodes to display if the custom field value is true. I'm not understanding the logic to do this. So basically, if there is a twitch video and a own3d video I only want the ...
3 votes
2 answers
4k 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 ...
  • 1,111
0 votes
2 answers
2k views

How to conditionally hide author name on Single.php if category is "news", otherwise if category is something else display author name?

I would like to be able to conditionally hide the author's name on the Single.php if the Category name is equal to "News" and otherwise if the category is something else hide it. How do I go about ...
  • 1,111
1 vote
5 answers
778 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 ...
  • 165
0 votes
1 answer
43 views

Template tag for /page/# structure

I'm trying to find a template page (or conditional statement) that will target: http://url.com but not http://url.com/page/2/ home.php and front-page.php seem to target both. The front page ...
1 vote
1 answer
128 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' => '9'...
5 votes
3 answers
4k 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"> <p&...
  • 4,491
1 vote
2 answers
708 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 ...
  • 81
0 votes
2 answers
1k views

Conditionals if tags exist?

I have the following code to display tagged articles with the same name as the page title, but I only want the to appear if the tag exists, otherwise it just says 'Related Articles' with no content. ...
  • 3
1 vote
1 answer
1k views

Proper syntax for simple conditional bloginfo language

I need to do something like this: <?php $bloginfo = get_bloginfo( 'language' ); if($bloginfo->en-US){ the_time('jS F Y'); }else{ the_time('d/m/Y'); }; ?> I cant find the proper ...