Questions tagged [conditional-content]

The tag has no usage guidance.

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

How to display image on condition that a selection has been made

I have a custom post type 'Holidays' and a custom field (created using Advanced Custom Fields) called 'activity_rating'. The activity_rating field is a select dropdown with values 1 to 5. If the ...
0 votes
2 answers
1k views

Using Switch Statement to Change Image According to Last Digit of Topic ID

I am trying to build a function, which gives out different image-urls, according to the last digit of bbp_get_topic_id(). This is, what i've got so far: function bg_image_topic_titlearea() { $...
0 votes
1 answer
858 views

Allow users to only CREATE one single (custom) post

I created a custom post type with taxonomy and now want to allow users (of a specific user group) to post only one single post in a specific category. If the user has already posted a post, he can ...
1 vote
2 answers
149 views

check if post is set to "password protected"

I'm trying to find a way to show different content if a post is set to "password protected", once the user entered the correct password. I want to show the price of an art piece only on ...
0 votes
1 answer
31 views

Display a block conditionally based on user input button

I am looking to put 2 donation forms on a page using a shortcode (or block) and I want them displayed based on currency selected by user,So for instance a user comes onto the page he will see 2 ...
0 votes
0 answers
55 views

Conditional display based on ACF checkbox

I have an ACF checkbox sub field in a group field on an options page. It has 4 options, and is set to return “Value”. I am trying to make a series of radio buttons that correspond to these options in ...
0 votes
1 answer
1k views

How to display content If function exist/condition true?

I've created my custom posts. Data from the same is displayed in let's say single-custom-post.php. Now to clean that file and to remove 100 lines of code, I want to make a new file (let's call it ...
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. ...
15 votes
9 answers
42k views

Why isn't is_page working when I put it in the functions.php file?

I have page called "Apple", the page's ID id 2533. In page.php file I have line: echo $bannerimg And this function in functions.php: if ( is_page( '2533' ) ) { // also tested with 'Apple' ...
0 votes
0 answers
25 views

Dynamic Buttons According to URL parameter

I am working on a WordPress Site. I just want to add a button on a page and track its behavior. My main question is when I create a campaign URL, I just want to change button behavior according to the ...
1 vote
2 answers
9k views

Conditionally hide or show woocommerce product variation in fontend by custom field

I have added a custom field (checkbox) to product variations with the following code: /** * Create new fields for variations * */ function variation_settings_fields( $loop, $variation_data, $...
0 votes
1 answer
30 views

Getting false for is_home() on Posts page

I've made a child theme of Twenty Twenty theme and want to display the posts/ category archive pages in flexbox grid. However, none of the conditional tags I'm hoping to check outside the loop (...
0 votes
0 answers
66 views

wp_enqueue_script JS code runs too late (after user begins interacting)

The issue is that we need to replace some HTML based on the user's user agent string but by the time the JS code is loaded and runs, the user is already interacting with the page. Is there some way to ...
0 votes
1 answer
61 views

Conditionally run function based on custom meta value?

I’m looking for a way to conditionally display an image within certain Woocommerce hooks that I choose based on whether a value is true within a custom meta field for the products on my site. For ...
0 votes
1 answer
20 views

Target a page with query

I have those 2 pages that are created from a plugin (see the plugin https://zombify.px-lab.com/frontend-page/, just login and choose a post type, check the url): https://www.domain.com/post-create-...
0 votes
1 answer
589 views

Give a condition to a wordpress menu item to change its offerid for each landing page I create

So my wordpress site has a one header and one footer with a big CTA as one of the menu items. I want to create a bunch of landing pages but I want to be able to change the offerid in the url for each ...
136 votes
8 answers
370k views

How do test if a post is a 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 in code like this: if ( is_single() ) { // Code here } I want code testing for only ...
0 votes
2 answers
158 views

Custom wp_query inside a conditional stament inside a template part doesn't work: why?

this is a bit messy and I cannot understand why my approach isn't working or what my error is. I'm using a template part to include a custom wp_query into my theme. I'd like to have two different ...
2 votes
1 answer
69 views

How to do conditional publishing?

I am trying to write a plugin that will stop a user from publishing (or updating) a post if a given condition is not met, for example, if the title of the post is already being used in a different ...
0 votes
1 answer
44 views

Loading a stylesheet conditionally & verifying CSS

There are several posts similar to this problem, but I need to still ask for help... The need is to change the column heading for posts if the Archived Posts page is selected in the menu (normally '...
0 votes
1 answer
73 views

How do I make content only load on desktop? [duplicate]

In order to improve the performance on mobile, I want to load some of the content on one of my sites only on desktop (this is content that is also not clicked on mobile). If I simply hide it via CSS, ...
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 ...
0 votes
1 answer
689 views

How to check if the current page is at a specified path in the URL?

I have a page marked as the Posts page that lists most recent blog posts. It is at path /blog. I want to know when the user is on this page so that I can display a list of categories of blog posts at ...
1 vote
1 answer
19k views

conditional statement for custom taxonomy

Struggling to find out how to achieve this, if it is at all possible. The equivalent of is_category but for a custom taxonomy I've set up. The taxonomy category if which being Taxonomy Name with 2 ...
1 vote
0 answers
203 views

Cluster WooCommerce products in each Category Archive by Tags assigned to products

Hello WordPress specialists. I am building my dream shop and I prepared a structure which I can not build now. Can you help me think about it? I prepared a product_cat categories which are based on ...
80 votes
10 answers
64k views

Enqueue Scripts / Styles when shortcode is present

What is the idea way to register/enqueue scripts and/or styles for use in plugins? I recently made a plugin simple plugin to add the user avatar/gravatar with a shortcode. I have different style ...
0 votes
3 answers
3k views

FacetWP - conditionally display facet labels

The following code generates a label for a facet (see sidebar). I would like to add a conditional statement that prevents the label generation is the facet if empty. $(document).on('facetwp-loaded', ...
-1 votes
1 answer
1k views

A conditional button

I wish to add a button to a page of my site that redirects the user to the signup page, if he is not a registered user, and to another page of the site, let's say Test_Page, if he is a registered user....
1 vote
2 answers
1k views

Personalized message for each unique password-protected page

How do I provide two different personalized messages for two different password-protected pages? I'm able to personalize the default message using the code below, but I'm not sure how to add a second ...
0 votes
2 answers
256 views

How to hide a menu from public, but share content with a private link [closed]

I would like to create a menu or menu item that can only be seen with a private link. So the menu would house various pages, but the content can only be seen with a link that is shared. I have ...
0 votes
1 answer
982 views

Conditional Fields for Contact Form 7 not working and displaying [/group] in output

I'm trying to get Conditional Fields for Contact Form 7 up and running in WordPress. I'm using Contact Form 7 version 5.1.3 and Contact Form 7 Conditional Fields version 1.9.14. I'm trying to follow ...
0 votes
1 answer
23 views

How can i conditionally load taxonomy-{taxonomy}.php template php files through functions.php

I have a movie review site, i would like to conditionally load the taxonomies of actors and directors only if a option of my theme is active. At the moment in the root theme folder I have these 2 ...
0 votes
2 answers
392 views

Conditional formatting on data fetched from MYSQL

I'm not an expert in PHP and I'm trying to apply conditional formatting on data fetched from wpdb. To be fair, I'm trying to create shortcode for this. My motto is to fetch values for $previous_marks &...
0 votes
1 answer
84 views

Conditional Fields depending on checkboxes

I'm currently trying the following (simplified objects): I have a bunch of "objects", which are cities. Each city has a relating country (even though I'm not sure how to implement this relation, yet),...
1 vote
1 answer
107 views

Prevent update of custom user profile meta field on the front end after 1st entry

I have an e-learning website that issues an official certificate of completion when a students complete their training course. The user profile name on the account can be used as the student name when ...
0 votes
0 answers
50 views

Find and print first <li> entry from Wordpress post in custom excerpt?

I want to create a custom excerpt for an education website. It has posts that contains and listing. I want to print the first child of ul and a first child of ol tag from the post. Currently, I ...
0 votes
3 answers
20k views

Conditional required fields for Wordpress Contact Form 7

I know this might be considered off topic but I am not sure where else to post this as it also pertains to WordPress as well as the plugin Contact Form 7. If you know where I should post this other ...
0 votes
1 answer
18 views

A little stumped - first WordPress theme

I am going through an online Udemy course alongside it I'm building my own little website. The website has 4 pages 1 of them a front page that I've created front-page.php and the rest of the pages ...
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;...
0 votes
1 answer
22 views

I'm trying to create an if statement that will only display my button link for tickets if its under 'admission-event'... what is wrong with my code?

<!-- column links --> <div class="col-md-3 offset-md-2 links"> <?php if ( is_category( 'admission-event' ) ) { ?> <a href="https://www.eventbrite.com/d/ut--salt-...
0 votes
2 answers
43 views

Adding if statement

I'm pretty new to PHP however have managed to put together a site I'm happy with. Once small issue I am having is that I would like to add content for users with specific roles, this means adding an ...
0 votes
1 answer
877 views

Understanding and using did_action() in a conditional statement

I'm working with Genesis Framework in a custom theme, but this is not a question "genesis-specific". I need to populate the sidebar of my pages (not posts) conditionally. The condition is to check ...
0 votes
1 answer
582 views

Can I set up a hover animation in CSS depending on a PHP conditional?

I created a 'Light' theme and 'Dark' theme in the WP dashboard (via Advanced Custom Fields) that will determine how a series of buttons will look, depending on which theme is selected: ...
0 votes
1 answer
124 views

Use modulo condition in ACF repeater Field

I want to make a modulo condition in my ACF Repeater field. In a while loop, I want my code different if $j is odd or even. My code: <div class="container grow mt-5"> <h1 class="text-...
0 votes
1 answer
477 views

Adding a template part as part of a shortcode

I am using "Ultimate Member" plugin to allow users to register because I want some content to be restricted for not signed-in users. According to their documentation, there are a few shortcodes for ...
0 votes
1 answer
88 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
1 answer
304 views

WP conditional site logo and header block

i have a customer who had 3 different sites and they wanted to bring all 3 sites under one umbrella site. however, each of the companies have different logos. when i define a logo for the site, it ...
0 votes
1 answer
1k views

Change Login or Logout text based on status

I'm trying to display text in a button in the header that says "LOG IN" or "LOG OUT" depending on the visitor's status. The button calls a slider action, so I just need to change the text displayed on ...
0 votes
2 answers
2k views

Is_front_page inside header.php is always returning true

I have a page that I designated as my front page using the reading portion of settings in the dashboard. When I place a script inside of an if statement using is_front_page in functions.php, it only ...
0 votes
1 answer
152 views

How to make widget appear conditionally

I hope you can help. I have two pieces of code that I do not know how to pair. I want my widget to only appear on posts and furthermore only if one specific category is picked. Whenever I try to put ...

1
2 3 4 5 6