Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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

0
votes
1answer
23 views

How to add custom PHP code in post header?

In header.php i want to add : 1. For home page : link rel="alternate" href="/fr/" hreflang="fr-FR" 2. For custom single post : link rel="alternate" href="/fr/category/post-name/" hreflang="fr-FR" ...
0
votes
0answers
14 views

Contact Form 7 Conditional Logic & Dynamic Text Extension Conflict

I am trying to create a form where depending which select field you choose, it will change the form and send it to that specific selection. The Problem: I can get the conditional logic working, its ...
2
votes
1answer
25 views

When is is_admin() available?

I see a lot of plugins that consist of a class that is instantiated in the same file, eg: class My_Plugin { function __construct() { add_action('init', array( __CLASS__, 'baz' ) ); } ...
0
votes
1answer
16 views

How to get value from radio buttons meta box, and return different contents?

I have a multiple checkbox type question (using Ultimate member) storing values as user meta. The question basically asks the user what he wants, and according to what he wants, I would like my ...
0
votes
0answers
24 views

adding an action inside if condition not working

This is my function $enable = false; //if false is provided then the action should run and remove the breadcrumbs if($enable ===false){ add_action( 'init', 'woo_remove_wc_breadcrumbs' ); ...
0
votes
2answers
59 views

I need use is_single in functions.php

I need to use validation is_single('wordpress') in file functions.php. But the function is_single() does not work in the file functions.php. What can I do so that I can use is_single() in file ...
0
votes
0answers
25 views

Why is_page() returns false when visiting the static page declared as “posts page”

First of all, sorry if this is a duplicated question... But I haven't found it in the same terms as I'm asking. I'm surprised because when checking the conditional is_page() in a function executed ...
1
vote
0answers
22 views

How To Conditionally Include A Short Code Depending On The HTTP_REFERER [closed]

I want to show a form at the end of my purchase-confirmation page only in the case where the previous page / HTTP_REFERER is the checkout page. I've tried lots of different ideas. For example, I was ...
0
votes
0answers
30 views

is_page not triggering

Here is my code: add_action('template_redirect', 'ep_tags_redirect_lockout'); function ep_tags_redirect_lockout() { if ( is_user_logged_in() ) { return; } //echo 'XXXXXX'; if (...
1
vote
1answer
24 views

Calling is_single() outside the loop

The file required doesn't load on single posts, it doesn't load anywhere! If I removed the is_single() function I can get it to work. My question is how I can check if the current page is a post? I ...
-1
votes
0answers
37 views

How can I change my title tag format for pages

I am currently designing a custom WordPress theme from scratch and designing the header.php part now. I was coding for the title tags and when I was done and tested, everything was alright excepting ...
0
votes
1answer
17 views

Alt Image Wordpress [closed]

When I use a seo tool in my blog, the tool has a lack of alt in the image of the site logo, but only in the urls of the posts (in the homepage the tool can identify the alt of the logo, which is the ...
0
votes
1answer
32 views

Undefined index for default custom theme option

I have a custom theme option that allows the changing of logos. There are 3 logo options: option1, option2, and option3. Upon theme activation, the default "option1" logo appears, but above it I get ...
0
votes
2answers
30 views

is singular and is home not working

I am creating a theme and i have added custom hooks to make the developement easier. when using the code in functions it works in all pages. the code is below add_action('before_footer','...
0
votes
2answers
31 views

Additional conditions tags to work

Im trying to get this simple condition tag to work . Im having no luck // If we are logged in, and NOT an admin and NOT on specific page... if ( is_user_logged_in() & !is_admin() ) & !is_page(...
0
votes
0answers
174 views

is_checkout() - conditional tag not working correctly

I am trying to echo out some text but only on the checkout page. I have this in a PHP file called checkout_text.php if ( is_checkout() ) { echo 'my text'; } And then in functions.php I am ...
0
votes
0answers
124 views

Wordpress, AJAX and pre_get_posts using conditional tags

I have a page that returns a list of posts in a custom post type. This is generated by a third party plugin. I want to omit the posts that are using a custom post status 'template'. Really the only ...
0
votes
1answer
174 views

Gravity Forms, multiple conditions in shortcode

Gravity forms offers a shortcode for conditional display based on responses. [gravityforms action="conditional" merge_tag="{:3}" condition="less_than" value="30"] Your value is less than 30 [/...
2
votes
1answer
20 views

How to check if an action is already fired?

How to check if an action is already fired in a function for example: function foo() { // checking if the action 'wp' is fired if( !action_fired('wp') ) { trigger_error('invalid call'); ...
0
votes
2answers
27 views

Can this code be concatenated?

I realise this is perhaps more of a php question, but it relates to WP use. Can the example below, be modified (and if so, how?) to fully concatenate the 2 echos rather than having them separate? if....
0
votes
1answer
54 views

How to add theme customizer control to specific page?

I would like to have something like: if (is_post_type_archive('my_post_type')) { $wp_customize->add_section(...); $wp_customize->add_setting(...); $wp_customize->add_control(...);...
0
votes
1answer
95 views

Why is this is_page conditional not working?

I am trying to do something I thought would be fairly simple. But it's not working, and has me stumped as to why. Any insight would be appreciated. I have a custom /woocommerce/archive-product.php ...
0
votes
1answer
36 views

Remove conditional tag from header

<?php if ( get_theme_mod( 'fukasawa_logo' ) ) : ?> <a class="blog-logo" href='<?php echo esc_url( home_url( '/' ) ); ?>' title='<?php echo esc_attr( get_bloginfo( 'title'...
0
votes
1answer
27 views

Conditional Statement with Multiple Terms?

I've set up a custom loop to output posts from a custom post type resource section I've created. Each separate resource has been categorized within two different taxonomies, one for the clinical area ...
1
vote
3answers
545 views

Redirect to checkout woocommerce failed

Bonsouir, I'm trying to redirect to checkout when a user add to cart a product just from the single product page, to be very specific from this page where everyone can see just the simple product Now,...
0
votes
1answer
21 views

Should I use template files or just use conditional tags in index.php?

With Template Files I am building a theme that has very few differences between templates. Right now I have it set up more or less like this: singular.php - Single pages/posts; full post content, ...
-1
votes
1answer
499 views

if is_page('slug')

Say I have a page domain.com/jibbly_bits and domain.com/jibbly_bits/small I'm trying to make a conditional statement where if it is a certain page or that page with a subpage after it. I've tried ...
0
votes
1answer
56 views

Generate Submenu based on Parent Page using If Statement

I need to pull a sub-menu depending on the parent page (or section) of the website. I have three sections (Our Inn, Our Restaurant, Activities) each requiring an individual submenu that my client will ...
0
votes
1answer
18 views

Conditonal tag or work around to identify page number of pagnation

I use a set of conditionals to define metatags on the various parts of my site. I noted that all pagination pages use the same metatags. If I can use a conditional tag or work around to identify the ...
0
votes
0answers
20 views

$_SESSION Not working after X amount of page views

I've written up a simple function that's output into header.php, which displays the login/register modal upon so many views in this case I've set it at 4, however its firing on the first view of my ...
1
vote
1answer
20 views

using conditionals on enqueue styles

I want to run my css code on a specific page in admin area. What is the best approach please? A: function register_style() { if (is_page..something) { wp_enqueue_style('style', ...
0
votes
1answer
70 views

How do I nest conditionals to identify sub-site & other criteria?

In a site's header.php which is in a child theme shared by the root and 4 other sites on a network (using MU configured in directories) I need to identify which site/sub-site is being shown and ...
0
votes
1answer
56 views

if is NOT custom post type OR is NOT page combination [closed]

I'm running a site with a LOT of plugins. I'm trying to deregister some scripts and css files on posts/ CPTs/ pages so they don't load where they aren't necessary. Basically, I'm deregistering when ...
1
vote
1answer
461 views

wp_head hook by page ID [closed]

I need help with this /* meta description to head */ add_action( 'wp_head','carlos_head_meta_page' ); function carlos_head_meta_page() { ?> <meta name="description" content="vale here"...
1
vote
2answers
736 views

is_front_page not working in functions.php

I am trying to include a CSS file using wp_enqueue_style conditionally on whether I am on the front page. I am testing for the home page with this code: if ( is_front_page() ) wp_enqueue_style ('...
0
votes
0answers
34 views

method to fetch entire tag list on archive.php

What I have Tried → <?php $taginto = get_the_tag_list(); if ( ! empty( $taginto ) ) { echo '<a class="categum" href="' . esc_url( get_tag_link( $taginto[0]->term_id ) ) . '">' ...
0
votes
1answer
144 views

is_single() conditional check inside ajax php function

I'm creating some dynamic content but I need to run a conditional is_single() check inside the php function add_action( 'wp_ajax_rando_func', 'rando_func' ); add_action( 'wp_ajax_nopriv_rando_func', '...
1
vote
4answers
1k views

Using is_page() in functions.php not working at all

Trying to run a custom script on a single page using is_page in functions.php not working at all. I have a function called load_gh_boards that would enquque a script, only on a certain page (79): ...
1
vote
1answer
895 views

How do I conditionally enqueue script for CPT single post type with plugin?

I'm writing a plugin that defines its own CPT "properties" and I want to enqueue a script specifically in single posts. It runs without my attempt at a conditional statement just fine but I don't ...
1
vote
2answers
118 views

wp_login Action hook with conditional tag

i tried to create a simple function to receive a email when a specify user is logged, i tried with $current_user->ID and also with wp_get_current_user() but not working. This is my code: function ...
1
vote
1answer
61 views

Will post_exists work for draft posts?

Can i check if a post with the title "great title" exists even if this post status is set to "draft" with the function: post_exists("great title") ?
0
votes
2answers
459 views

Multiple if statements with else for get_the_category [closed]

I created some code to return attachment categories, that looks like: <?php // Attachment Categories $categories = get_the_category($attachment->ID); if ($categories) { ?> &...
0
votes
1answer
106 views

How do I apply different headers to different pages using this template?

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <header class="pagecontent-header"> <?php the_title( '<span class="entry-title">', '</span&...
-1
votes
1answer
23 views

How do I combine these two conditionals? [closed]

I'm using two conditionals, which I want to combine into one: if ( !is_page(56) ) if ( !is_404() ) { // Do something. } The intent is 'if it's not page 56 or a 404, do something'. I haven't ...
0
votes
1answer
374 views

Check if custom post is a parent?

I am using the following query to list all posts within the post type 'services': <?php $args = array( 'posts_per_page' => -1, 'post_type' => ...
1
vote
3answers
1k views

Do I need to include 'else' and/or 'endif'?

I realise this may be a generic php question, but as it's related to WP I'm including it here. If adding a simple conditional to my page.php template, do I need to include an 'else' (for other pages) ...
0
votes
1answer
28 views

Hide sidebar and change layout Blog Page using is_page() function

I have two conditionals in my page.php, the first one to use col-12 or col-8 (bootstrap 4) and another to add or not the sidebar. See the code: col- <?php if(!is_page(array('cart', 'checkout', '...
0
votes
2answers
61 views

How do I modify the 'more' link in a feed

I use a function to modify the 'read more' link for posts. function modify_read_more_link() { return '<p class="read-more"><a href="' . get_permalink() . '">CONTINUE READING &raquo<...
0
votes
1answer
356 views

“Undefined variable: array” Error In Displaying Post Tag

I'm trying to display the post tags through a widget, I've following codes and getting error "Undefined variable: array": if ( $instance['stats_tag']['category'] ) { $posttags = ...
1
vote
2answers
341 views

Post tags show outside loop?

I'm trying to use tags of the single post, as meta keywords. I tried using this: <meta name="keywords" content="<?php the_tags('',',','');?>test<?php }?>"/> It works, but the ...