How to exclude AdSense Auto Ads on Homepage - wordpress

I just want to share what I can do after searching many times about this. This is for self notes but I know many people looking for this. So this code is using Conditional Tags and no need plugin to use this.

Just copy and paste this code in inside header, and of course adjust with your own settings.
<?php if ( is_single() || is_category() ) : ?>
** place your auto ads code here**
<?php endif ?>

Related

Wordpress page content variable

I am new to wordpress coding but familiar with standard HTML/CSS. With the help of various online tutorials I've finally gotten a good chunk of a simple HTML/CSS website converted to wordpress but Im missing out on some of the basics.
In this case, I am just trying to setup my template to work with the page.php file so that I can create pages through the wordpress admin console. I've figured out how to get the head.php, footer.php, and functions.php working for styles and js files but now I am struggling with what variable I need to place so that the title and content I enter into the page via the wordpress admin appears.
I've tried
1) using a div id=content to my page.php file --that didnt work
2) I've tried adding to my page.php file -- that didnt work
I cant seem to figure it out. Any help would be greatly appreciated. I am a definitley a beginner here so any help is greatly appreciated. Thanks!
This is a very basic template of a page.php in Wordpress.
<?php get_header(); ?>
<div>
<?php
if( have_posts() ) :
while ( have_posts() ) : the_post();
the_title(); // Outputs the title of the page
the_content(); // Outputs the content of the page
endwhile; // End of the loop.
endif;
?>
</div>
<?php get_footer(); ?>
Also, if you would like to store the title and content in php variables first, you can just call get_the_title() and get_the_content()
Please let me know if you are stuck.

restrict viewing photos and article content on a wordpress site

I have a question, and i hope i am posting in the right place, if this topic belongs to another forum, please guide me where to post it.
the question is: i have a website created with WordPress and i am using the Jupiter theme, i need to hide some content (like hiding the last half of the article in a page) and disable the photos to be enlarged unless the visitor is a registered user, i need to know how to do that, and if there is a plugin to do that, i have tried "layered-popups-for-wordpress" and "optin-content-locker-layered-popups-addon" but they didn't work properly.
It might request a lot of effort for you to edit the theme on your own...You can use the_excerpt() insetead of the_content() for display info, and add a rule that only registered members can see, something like
if(is_user_logged_in()) {
the_content();
} else {
the_excerpt();
}
Do this while in the loop, of course...
These plugins might help you though
https://wordpress.org/plugins/tags/paid-content
If you're using WPMU might try this one
https://premium.wpmudev.org/project/pay-per-view/
I don't know of a plugin that does this automatically, but you can do it yourself if you are willing/able to do some minor theme development. Make a child theme of your Jupiter theme, and copy over the file content.php. There will probably be some part of the code that looks like this:
<?php if ( is_search() ) : ?>
<?php the_excerpt(); ?>
<?php else : ?>
...
Or something like that. The point is, the theme should already be set up to serve excerpted content for a search. You could either simply add code like this:
<?php if ( is_search() || !is_user_logged_in() ) : ?>
<?php the_excerpt(); ?>
<?php else : ?>
...
Or you could customize what non logged in users are seeing like this:
<?php if ( is_search() ) : ?>
<?php the_excerpt(); ?>
<?php else if (!is_user_logged_in()) : ?>
<!-- Your custom code display here -->
<?php endif; ?>
Hope that's helpful!
In order to hide certain parts of your content with just a simple shortcode you may give "Restrict Anonymous Access" plugin a try:
https://wordpress.org/plugins/restrict-anonymous-access/
Examples:
[member]My restricted content …[/member]
This shortcode can be placed wherever you need to hide something from logged-out users or even users of a certain user role can be addressed:
[member role="author"]My restricted content to users below author role …[/member]

Custom Wordpress sidebar not being retrieved

I'm tuning up a website made with Wordpress and I'm facing a small inconvenient:
I want to use a custom template for the posts in a specific category, so I have a single-4.php file that gets me a custom php file for any post in cat.id 4. That works great, now for the problem...
PROBLEM -->
I want to display a custom sidebar as well, so at the end of the single-4.php I add:
<?php get_sidebar( $evento ); ?>
As instructed in the Wordpress Codex, expecting to get my sidebar-evento.php file used istead of the default sidebar.php. But it doesn't work, instead it will just use the default behaviour instead. I have also tried "'single-evento'" instead. I know that the code line is being used because if I remove it, the sidebar area breaks ( dissapears and the page breaks).
My suspicion is that the Custom Sidebars plug-in is catching up right after I call for any sidebar and regardless of which one I'm requesting, it gets replaced. But it doesn't make much sense really. Because as you can see in my sidebar-evento.php:
<div id="right">
<h3>LINE TO CHECK IF SIDEBAR-EVENTO.PHP IS SHOWN</h3>
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<?php endif; // end sidebar widget area ?>
<?php if ( ! dynamic_sidebar( 'sidebar-3' ) ) : ?>
<?php endif; // end sidebar widget area ?>
</div></div>
Both things should happen: A) I get my custom text, then B) I get the other custom thingies as determined by the plug-in.
I hope I've been clear about what my problem is. Please bear in mind for your response that I have no PHP knowledge, I only do HTML and this is a sort of -charity- project, so I try to learn as I go. Meaning: step-by-step might be necessary! heh. Sorry!
Thank you very much in advance.
Try:
<?php get_sidebar( 'evento' ); ?>
This should pull in sidebar-evento.php

custom wordpress page

I'd like to implement a custom post retrieval page in wordpress. Basically, I'm using AJAX to call this page that will be passed a post ID and retrieve certain data from that post.
Note: please don't mistake this as a template question. I do not want a template for one single page -- I am looking to make this page query multiple different posts based on postID and return certain data from that post.
So I tried creating a page
<?php
$args=array(
'p'=>'77'
);
$friends = new WP_Query($args);
?>
<?php if ($friends->have_posts()) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php else: ?>
<p>Sorry, no posts are available.</p>
<?php endif; ?>
But this does not work since it is not loading in the wp functions to handle the query.
Thanks in advance for any help!
You have to include the wp-blog-header.php file. If the page you are creating is in your theme's folder then you would put something like this at the top of your code
<?php require_once ('../../../wp-blog-header.php');?>
I think I guess what you are trying to do, and it sounds like you are going about it the wrong way. Do not make a 'new page' in the admin interface. What you want to do is serve up a file (JSON, XHTML fragment, whatever) to your Javascript and include in it WP data, right? I know that problem, having used it in some of my plugins.
There are two techniques:
(1) This is what you need to do: make a new plugin (just a loose php file in wp-plugins with the same format header as the other plugins in there). Write your function along these lines:
function mydatapage(){
if (...$_SERVER['REQUEST_URI'] == the one I am using ...) {
$args=array(
'p'=>'77'
);
$friends = new WP_Query($args);
if ($friends->have_posts()) :
the_post();
the_title();
the_content();
else:>?
<p>Sorry, no posts are available.</p>
<?php endif;
die();
} //else do nothing and leave WP to serve the page normally
}
//Crucially:
add_action('init', 'mydatapage');
What that does is do a lookup when pages are loaded to see if the url matches the one you want to hijack and use to send your custom data. If it is, you send the data/file/whatever you feel like and exit (die).
Give a shout if you want more detailed syntax. It is a bit messy, but works well.
(2) Directly call your plugin file. WP will only handle files that do not already exist, and leave the rest to Apache. That means you can make a plugin file and call that directly using the .../wp-plugin/myfile.php url. You would need to include some of the WP core files to get things like WP_Query to work. It is marginally more fragile a method.

Wordpress: Removing posts in "The Loop" using filters

After reading the Wordpress documentation, I realized you can remove posts from the index using filters inside "The Loop", e.g.:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- The following tests if the current post is in category 3. -->
<?php if (in_category('3')) continue; ?>
<!-- display normal post -->
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
What I'm wondering is if there is a filter/hook to filter posts in have_posts() without modifying the template. So far, I found options to change the results, but not remove results form the result set.
You can hook into 'pre_get_posts'.More info here: http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts. As the article describes:
This hook is called after the query variable object is created, but before the actual query is run.
Using query_posts(), you can override the query variables and exclude any posts. The link has some decent examples on how to do this.
So you want to remove it from displaying but still have it 'there' incase you decide to show it later? Not really clear on what you want to do.
As one example, in the past I've used Query Posts to keep categories off of my homepage: http://codex.wordpress.org/Template_Tags/query_posts#Exclude_Categories_From_Your_Home_Page

Resources