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 custom-header.php) and then just echo or call that content. Since I've built custom post as a plugin, ideally would be nice to call it if plugin is active, however I don't know how to finish this because one statement is if myplugin is …
Category: Web

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-page/?type=story https://www.domain.com/post-create-page/?type=trivia The plugin is making use of custom post type. I have been trying to target them if (is_page ('post-create-page') && ... ) with get_query_var by trying to pass the $qvars to add_filter( 'query_vars' but I am not sure how to do that. Could some one help me how i could target those 2 …
Category: Web

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 landing page for that big CTA so I can track. By offerid I mean http://www.example.com/customers/?offerid=weyhw68963. I'm am stuck on how to do this since the menu is a global menu and the link is the …
Category: Web

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 holiday has been rated as very easy (1) then I would like to display a certain image (1 star), if the holiday has been chosen to be easy (2) then I would like a different image to be displayed (2 stars) etc all the way to 5 (very …
Category: Web

How to display conditional menus with Twenty-twenty two theme?

With earlier versions of default Wordpress themes I was able to display an alternative main menu depending on the category of the given page or post, using this filter in my functions.php: ( In this example we have German and French categories that display menus named German or French. All other categories display the menu named English. ) function my_conditional_menus( $args = '' ) { if (in_category('german')) { $args['menu'] = 'german'; } elseif (in_category('french')) { $args['menu'] = 'french'; } else …
Category: Web

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() { $letztezifferimgs = substr("'.bbp_get_topic_id().'", -1); switch ($letztezifferimgs) { case "0": echo "https://test.bewusstewelt.de/wp-content/uploads/2016/10/Blockaden-lösen-2.jpg"; break; case "1": echo "https://test.bewusstewelt.de/wp-content/uploads/2016/09/Das-Leben-ist-ein-Spiel-2.jpg"; break; case "2": echo "https://test.bewusstewelt.de/wp-content/uploads/2017/02/Bedürfnisse-erkennen-3.jpg"; break; case "3": echo "https://test.bewusstewelt.de/wp-content/uploads/2016/08/Selbsterkenntnis-sich-selbst-finden2-1.jpg"; break; case "4": echo "https://test.bewusstewelt.de/wp-content/uploads/2016/11/Reinkarnation-Wiedergeburt-2.jpg"; break; case "5": echo "https://test.bewusstewelt.de/wp-content/uploads/2016/10/Intuition3.jpg"; break; case "6": echo "https://test.bewusstewelt.de/wp-content/uploads/2016/07/Manchmal-muss-man-loslassen-3.jpg"; break; case "7": echo "https://test.bewusstewelt.de/wp-content/uploads/2016/07/Manchmal-muss-man-loslassen-3.jpg"; break; case "8": echo "https://test.bewusstewelt.de/wp-content/uploads/2017/02/Pfad.jpg"; …
Category: Web

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 only edit his own post (I already have the PHP for that). I found a lot of solutions that users can only post in a specific category or only edit their own posts, but no-where an conditional that the user can …
Category: Web

can you help review CCCP (Conditional Cookie Content Post) and help to create a block?

I just need for one site with a front en video with sound to remove the video after two view I achieved to make it with cookie to show/hide a class can be seen a demo at https://accedinfo.com/2021/12/28/wordpress-masquer-ou-afficher-un-bloc-apres-x-vues/ and this is the used code it works with post or blog but need to adjust everything inside Maybe somebody can use this to create CCCP = Conditional Cookie Content Post bloc ? (and no, i'm not an old cccp citizen) /* …
Category: Web

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' $bannerimg = 'apple.jpg'; } elseif ( is_page( 'test' ) ) { $bannerimg = 'test.jpg'; } elseif ( is_page( 'admissions' ) ) { $bannerimg = 'admissions.jpg'; } else { $bannerimg = 'home.jpg'; } The point is the $bannerimg echoes "home.jpg" on every page, including Apple, test …
Category: Web

Display post content based on user's selection from dropdown

I have a set of dropdowns pupulated with auto-moto data, eg. Select car brand: (list of all brands), when I select eg. Brand1, then I get to select Car model from another dropdown, ... etc. Now I have created few posts, each post has some pricing information for the selected car. What I want to do is based on the selected car, I want to show specific post. Currently I was able to get all the dropdown settings with WPForms …
Category: Web

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 behaviours throughout the theme, so I'm using a conditional statement inside the template part to output two different loops. In my front-page.php I call the template part with get_template_part() using the $args option: <?php get_template_part('template-parts/modules/moduli-offerta/offerta-figli','lista', array('tipologia' => 'lista') ); ?> In my …
Category: Web

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 post (I am using a custom post type, if that makes a difference). I wrote a function that gets called through the 'transition_post_status' hook to attempt to catch the post before it gets published or updated in the database, so …
Category: Web

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 'Highlighted Posts' is displayed in the heading.) This is illustrated in this screen shot; note the only difference is the text in the ::before::after element: Here is the code in my child theme functions.php file: function register_arch_posts_stylesheet() { wp_register_style( 'arch-post-stylesheet', get_stylesheet_directory_uri() . '/arch-post-stylesheet.css' …
Category: Web

How do I make content only load on desktop?

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, it is still loaded, so I guess it won't really speed up the site much. Is there a way in WordPress to actually not load some of the content on mobile, so it is only loaded on desktop?
Category: Web

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 posts, so if you log in to the admin area from a mobile device you're redirected to the post listing and the admin menu isn't even available. Ideas?
Category: Web

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 the beginning of the page. I already did this in singular.php and in the rest of the cases in index.php. For me is_home() returns true when on the landing page. And I use its behavior in …
Category: Web

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 taxonomies: Taxonomy One and Taxonomy Two. But this: <?php if ( has_term('taxonomy-one' ) ) {?> <div class="test" style="color: red"><?php the_field('field_name'); ?></div> <?php } elseif ( has_term('taxonomy-two' ) ) {?> <div class="test" style="color: green"><?php the_field('field_name'); ?></div> <?php } ?> There doesn't seem to be any …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.