Wordpress - if is_plugin function? - php

So, I have been trying a couple of things but I can't figure it out.
In my header.php file I have a simple PHP line (custom-made Wordpress theme):
<?php if ( is_page('Home') || is_404() || is_search() ) { echo ""; } else { echo "<h1>". get_the_title() ."</h1>"; } ?>
This was working GREAT until I was required to install "The Events Calendar" plugin and adapt it to my theme.
The plugin allows me to go into its settings and create a URL slug, in this case I named it "reunions" and I did "reunion" slug for single events. So, logically I should be able to do this:
<?php if ( is_page('Home') || is_page('reunions') || is_page('reunion') || is_404() || is_search() ) { echo ""; } else { echo "<h1>". get_the_title() ."</h1>"; } ?>
But this didn't work, additionally I tried these two things but no luck:
$pagenow == 'the-events-calendar.php'
is_plugin_active( 'the-events-calendar/the-events-calendar.php' )
My work around would be to manually add <h1>(title)</h1> to each page, there's gotta be a way to do this. Is it possible to create a is_plugin('the-events-calendar') function to check for the plugin and disable the H1 line?
Any help would be greatly appreciated :)

You could use is_singular() function to check if the current post is of plugin's event custom post type, like this:
<?php if ( is_page('Home') || is_singular('tribe_events')...
Update:
You could also use has_term() function, to check for specific slug, like this:
<?php if ( is_page('Home') || has_term('reunions')...

Related

Hide content in posts and category by id in Wordpress

I am trying to hide a script in some posts and specific categories, here I leave a demonstration of what I have done but it is not working, since when using! Is_single (1001) what it does is hide all the content in it site.
My codes:
<?php
if ( !in_category(118) && !in_category(137) && !in_category(121)) {
?>
<script></script>
<?php } ?>
This is what I've been doing:
<?php
if ( !in_category(118) && !in_category(137) && !in_category(121) && !is_single(1001)) {
?>
<script></script>
<?php } ?>
For categories it does work but when I add! Is_single (1001) the script is hidden all over the site.
I hope your help, I am starting to learn php in WP.
first of all your conditions looks little doubtful, cause it's comparing all the conditions when you use && instead please use || (OR) condition if you are trying to enable or disable script on those conditions.
Second: i dont think WP has function like in_category to check, but i guess you should use is_category()
Third, please add id in array if you have multiple
for example:
!is_category( array( 9,12,19,30 ) );
!is_single( array( 1009,102,119,330 ) );
hope that will work!

How do I properly add an "or" clause to a php snippet?

I currently have this php snippet in a WordPress-based website:
if ( ! is_singular( 'page' ) || ! current_theme_supports( 'genesis-after-entry-widget-area' ) ) {
return;
}
I would like to have some type of "or" clause, where I can tell the server, "if this item is a page or a portfolio type, then return."
Basically, would like to include the types: "page" and "portfolio" in this snippet.
But I am unsure how to do this without redeclaring the function all over again.
Any guidance would be greatly appreciated!
I think what are you looking for is WordPress get_post_type function:
if (get_post_type() == 'page' || get_post_type() == 'portfolio') {
return;
}
I'm not a wordpress developer, but based on their is_singular documentation, it seems that the function accepts an array of custom post type values. So you should be able to do something like this:
if (is_singular(array('page', 'portfolio'))) {
return;
}

Conditional tags in wordpress

Sorry for the trivial question but I'm not very skilled in php...
I need to display a slideshow on every page of my wordpress site except in one (sponsor).
I tried with this code but does not work.
<? php if (! is_sponsor ()) {do_action ('slideshow_deploy', '3484'); }?>
Where did I go wrong?
The normal code to display the slideshow is:
<?php do_action('slideshow_deploy', '3484'); ?>
Thanks in advance!
If you want to disable the slider on the page with slug "sponsor", try with the following code:
if( !is_page('sponsor') ) {
do_action('slideshow_deploy', '3484');
}
If you want to disable the slider on posts from post type "sponsor", try with the following code:
if( !( is_single() && get_post_type() == 'sponsor' ) ) {
do_action('slideshow_deploy', '3484');
}
There is no such thing as is_sponsor
to not display it for that single page
create a new page template and completely remove
<?php do_action('slideshow_deploy', '3484'); ?>
here is the naming structure
http://codex.wordpress.org/Template_Hierarchy

is_home not working in wordpress when using templates

I have a div of services (full width) which I only want to display on the home page of my Wordpress site. I have used the conditional tag if(is_home()) and it is working fine. But when I added a new template this division is showing up in the template page, too. I tried using:
(if(is_home())&&(!is_page_template('blog.php'))
...but unfortunately it is not working. I have also tried it using ID and slug, and yet still this particular div is coming in the template.
I some how want this div to show up only on the homepage. You can see the services div here. The same is being displayed here, but not in other inner pages.
Use is_front_page() instead.
See Here
This code
<?php if (is_home()) : ?>
// yes, home page
<?php else : ?>
//no, not home page
<?php endif; ?>
Simply use
if(is_home() && !is_page_template('blog.php'))
Everything Should be in one condition
You can do it with any of the following conditional tags
if( is_home() && !is_page_template( 'page- template-Blog-php' ) ) {
// service div here
}
Note: If you are using template in any folder you need to give folder path too.
For example: If you are placing all the templates in 'templates' folder your code will be:
if( is_home() && !is_page_template( 'templates/page-template-Blog-php' ) ) {
// service div here
}
or you can try following code:
if( is_home() || is_front_page() ) {
// service div here
}
Braces wrongly placed:
if( (is_home()) && (!is_page_template('blog.php')) )

Function Reference/shortcode exists in wordpress

how can i understand a short code is exist in my wordpress post?
[tbps id="1"] is the short code . Where id may vary . ie 2,3 ...
i paste this code in wordpdpress post namely mypost ,it is working .So how can i get the shortcode which exists in wordpress page (in mypost). i don't know how to use this code
<?php
if ( shortcode_exists( 'yourCondition ' ) ) {
//Here i don't know how to use 'yourCondition' .Because condition
//is varying .It may be [tbps id="1"] ,[tbps id="2"] ,[tbps id="3"] etc
}
?>
<?php
if ( shortcode_exists( 'yourCondition ' ) ) {
// The [gallery] short code exists.
}
?>
you can try
In wordpress 3.6 and above you can do this... Say your shortcode like this... [fts youtube username=GoProCamera vid_count=5]
// Detect if the shortcode exists in a post page or widget
global $post;
if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'fts youtube') ) {
wp_enqueue_style( 'fts_youtube_css', plugins_url( 'youtube/css/styles.css', dirname(__FILE__) ) );
}
This works even if you use multiple shortcodes on a page, post or widget, and of course will not duplicate your styles or js because you are enqueueing them. Tested and confirmed. https://codex.wordpress.org/Function_Reference/has_shortcode

Categories