wordpress search should not return no-index'd pages - wordpress

I am using the wonderful Yoast plugin for all sorts of things, but largely to no-index and no-follow pages. We are a PPC based site so therefore we removed search. Now the client wants it back in but I need the wordpress built-in search NOT to return a large number of no-indexed pages.
I know you can build in to exclude various meta descriptions.
I was going to adapt this as a start:
https://css-tricks.com/forums/topic/using-wps-pre_get_posts-to-exclude-post-with-meta_key/
Question - What is the term I am looking for - meta-no-index=no??
Why doesn't Yoast do this by default?

You'll need to edit the robots meta tag that is outputted by the wp_head() function.
If using Yoast, this is the WP filter to change the robots meta tag content:
add_filter('wpseo_robots', 'yoast_no_search_noindex', 999);
function yoast_no_search_noindex($string= "") {
if (is_search()) {
$string= "index,follow";
}
return $string;
}
https://wordpress.stackexchange.com/questions/136220/remove-meta-robots-tag-from-wp-head

Related

Yoast plugin is not showing meta description and meta keyword

I am a newbie and learning new things every now and then. I recently set up Yoast on my WordPress website and I put title, focus keyword, and meta description for every single page of my website manually in Yoast widget. This shows up under the page but unfortunately the meta description and keywords is not appear on the page source.
In fact throughout the website same title and description is displayed. Is there any additional configuration required after installation of Yoast in header.php or somewhere in files?
You can add code to functions.php for showing focus keywords as meta-keywords in section of the page.
function set_head_keywords() {
$id = get_the_ID();
if (!$id) return;
$meta = get_post_meta( $id, '_yoast_wpseo_focuskw', true );
echo '<meta name="keywords" content="'.$meta.'" />';
}
add_action( 'wp_head', 'set_head_keywords' );
Answer from Yoast seo plugin is stated below:
We’ve removed the meta keywords feature in Yoast SEO from version 6.3. Meta keywords haven’t had a use for a long time, so their removal from our plugin has been long overdue.
Reference: https://kb.yoast.com/kb/meta-keywords-yoast-seo/
Google:
Google does not use the keywords meta tag in web ranking.
Reference: https://webmasters.googleblog.com/2009/09/google-does-not-use-keywords-meta-tag.html
Yahoo! Announced they no longer use the meta keywords tag anymore either.
Bing:
On 2014: Today, it’s pretty clear the meta keyword tag is dead in terms of SEO value. Sure, it might have value for contextual ad systems or serve as a signal to ‘bots plying the web looking for topics to target, but as far as search goes, that tag flat lined years ago as a booster.
Reference: https://blogs.bing.com/webmaster/2014/10/03/blame-the-meta-keyword-tag

Can I remove the JSON-LD schema that Yoast adds to my WordPress site?

I would like to remove the JSON-LD schema that Yoast applies to my WordPress site so that I can add my own. I have already added my own, and Google Structured Data Testing says that it is OK, but basically I have 3 separate JSON-LD schemas instead of two because of Yoast.
You can see what I mean here: https://search.google.com/structured-data/testing-tool/u/0/#url=http%3A%2F%2Fwww.yogabearpc.com
Yoast has added the WebSite schema and it seems unnecessary or even damaging?
I wanted to disable this because of the sitelinks searchbox and the fact that I don't have a search function that works globally, just on the blog. Having the search box enabled for me would have undesirable effects.
The easier option may just be to prevent Google using the sitelinks searchbox without having to touch the functions files. You can prevent Google using sitelinks searchbox on your site by using the following meta:
<meta name="google" content="nositelinkssearchbox" />
If you want to disable Yoast's JSON-LD all together then here's a snippet from my blog and the code I use on my site:
SOURCE
How to disable Yoast SEO Schema JSON-LD completely
function bybe_remove_yoast_json($data){
$data = array();
return $data;
}
add_filter('wpseo_json_ld_output', 'bybe_remove_yoast_json', 10, 1);
Login to your WordPress dashboard and head over to the editor
within the tab menu appearance, find your functions file (normally
named functions.php) and add the code below just before the PHP tag is
closed at the bottom.
Simplest way to completely disable the Yoast SEO schema JSON-LD
Add this line to functions.php file:
add_filter( 'wpseo_json_ld_output', '__return_empty_array' );
Source
If you want to disable just Organization or just Website, add this to your theme's functions.php file:
function bybe_remove_yoast_json($data){
if ( (isset($data['#type'])) && ($data['#type'] == 'Organization') ) {
$data = array();
}
return $data;
}
add_filter('wpseo_json_ld_output', 'bybe_remove_yoast_json', 10, 1);
Unless the data Yoast produces is wrong, there is no harm in having it. Quite the contrary, having more structured data is better than having less.
If having it is "unnecessary" depends on your definition of what is necessary. Some consumers might be interested in it, others not.
My guess is that Yoast adds a WebSite entity because of Google’s sitelinks searchbox rich snippet result, which allows Google users to search your site directly from the Google search result.

Yoast SEO plug-in removing canonical tag

I am currently using the wordpress seo plugin by yoast, and have run across a problem trying to remove the following tag:
rel="canonical"
The canonical tag is ok on a page such as blog.com/page/, however, on pages such as blog.com/page/2/ I don't want the canonical tag to show up.
I've done some googling and haven't been able to find quite what i'm looking for so im hoping stack overflow will save the day.
#bobdye Answer has no effect for me, but this works:
function wpseo_canonical_exclude($canonical) {
if (is_paged()) {
$canonical = false;
}
return $canonical;
}
add_filter( 'wpseo_canonical', 'wpseo_canonical_exclude' );
The WordPress SEO plugin has a filter you can use to disable the canonical URL on the pages you mention above.
In your functions.php file, add:
if (is_paged()) {
add_filter( 'wpseo_canonical', '__return_false' );
}
The WordPress function is_paged() returns true if the page being displayed is "paged" and the current page number is greater than one.
Returning false to the filter disables it.

WordPress Yoast SEO Plugin and opengraph tags

I have a wordpress page that is dynamic. WordPress SEO By Yoast adds opengraph tags to all pages which isn't a problem except on this one page.
Is there a way to overwrite the meta tags with more dynamic content?
Looking through the code of Yoast SEO, I found many "undocumented" filters you can use. Here is a list extracted from it:
wpseo_opengraph_author_facebook - Allow developers to filter the
Yoast SEO post authors facebook profile URL
wpseo_opengraph_admin - Allow developer to filter the fb:admins
string put out by Yoast SEO wpseo_opengraph_title - Allow changing
the title specifically for OpenGraph wpseo_opengraph_url - Allow
changing the OpenGraph URL wpseo_opengraph_type - Allow changing the
OpenGraph type of the page wpseo_opengraph_desc - Allow changing
the OpenGraph description wpseo_opengraph_site_name - Allow
changing the OpenGraph site name wpseo_opengraph_show_publish_date -
Allow showing publication date for other post types
wpseo_opengraph_image_size - Allow changing the image size used for
OpenGraph sharing wpseo_opengraph_image - Allow changing the
OpenGraph image. wpseo_twitter_card_type - Allow changing the
Twitter Card type as output in the Twitter card by Yoast SEO
wpseo_twitter_metatag_key - Make the Twitter metatag key
filterable wpseo_twitter_description - Allow changing the
Twitter description as output in the Twitter card by Yoast SEO
wpseo_twitter_title - Allow changing the Twitter title as output in
the Twitter card by Yoast SEO wpseo_twitter_site - Allow changing
the Twitter site account as output in the Twitter card by Yoast
SEO wpseo_twitter_image - Allow changing the Twitter Card
image wpseo_twitter_image_size - Allow changing the Twitter Card
image size wpseo_twitter_creator_account - Allow changing the
Twitter account as output in the Twitter card by Yoast SEO
EDIT:
A few things to remember:
Facebook scraps the url in the og:url tag (even if it's not the actual url you give it).
If you return false from the wp filter function, Yoast will not display that tag, so you can use it like that, and then manually add the tag somewhere else in your code where you need...
For example, here is some code to disable description and image tags for og and twitter:
function yoast_og_tag ($tag) {
return false;
}
$yfilters = [ 'wpseo_opengraph_desc','wpseo_opengraph_image','wpseo_twitter_description','wpseo_twitter_image' ];
foreach ($yfilters as $k => $f) {
add_filter( $f, 'yoast_og_tag', 10, 1 );
}
Yoast make various filters available. See their WordPress SEO API Docs article for a list of them. So, for example, if you wanted to change the opengraph type of a blog post with ID 86, you could use the wpseo_opengraph_type filter:
function modify_opengraph_type_p86( $type ) {
if ( is_single( 86 ) )
$type = 'video';
return $type;
}
add_filter( 'wpseo_opengraph_type', 'modify_opengraph_type_p86' );

Custom Plugin for wordpress with hierarchy of SEF pages

Here's my issue. My company needs a vendor database added to our wordpress website. None of the existing plugins will even come close to what we need, and we already have a mysql database with all of our information, so we need to create a plugin or something to do what we need.
These urls need to be direct-accessible and have SEF urls. So, for example:
mysite.com/vendors/
mysite.com/vendors/pipe-manufacturers/
mysite.com/vendor/bobs-pipes/
And, the custom content needs to appear inside the wordpress template.
There are really 2 options:
1) Find a way to write our application outside of wordpress, but find a way to bootstrap wordpress to show the header, footer, and sidebar.
2) Run the app from inside wordpress.
So I went for option #2. I created a new template file named "vendor.php", and began working. I added this code to my functions.php of my theme:
add_filter( 'template_include', 'xyz_template_check' );
function xyz_template_check() {
global $template;
$rqst = $_SERVER['REQUEST_URI'];
$ra = split("/", $rqst);
if ($ra[1] == "vendors") {
$template_file = get_stylesheet_directory() . '/vendors.php';
return $template_file;
}
return $template;
}
So what the above code does, if it sees the word "vendors" as the first part of the url after the site name, it sends you to vendor.php. This works PERFECTLY....
except...
Wordpress believes that the page is not found. It returns a 404 header, and NOT FOUND into the page title and breadcrumb.
Adding a PAGE called "Vendor Database" with the permalink "/vendors/" fixes the main page. But there will be literally hundreds of vendors and different categories. I cant be creating a custom page for each one. This needs to be dynamic.
So, how do I make wordpress give a 200, and supply an acceptable page title, breadcrumb, etc.
Don't even get me started on the danged wp_title filter. This did NOT work as documented. Although, it just occurred to me that this might be an issue with Wordpress SEO (the wp_title filter issue).
Anyone got an idea on this?
Ok got this. The solution was to use the rewrite api, as mentioned above, to look for the pattern /vendors/, letting it know that it was a valid URL. Coupled with my existing template override, this is what I needed.

Resources