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

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.

Related

How to add a separate Analytics for each website page in Wordpress

We have a WordPress installation that has locations as separate pages.
For example: mysite.com/colorado and mysite.com/alabama
We need separate google analytics for each of these as well as 1 for all of mysite.com.
Is there a way to do this with a WordPress plugin(s) or will we need to hand code some things?
Thanks in advance!
If I'm not mistaken, Google Analytics lets you view your analytics in a breakdown like that. That said, if you do need individual scripts, it would be relatively easy to program in. There may be some plugins that do this, but I'm not aware of any in particular, though a cursory glance showed plugins like Header and Footer Scripts that allow you to add scripts on a page by page basis.
Some themes also allow you to add SEO/Script settings per page/post. If that's the case, you can just open up each page and dump each script tag in the "header scripts" or similar section, and call it good. (Genesis is an example of a theme that does this).
If not, programming this would be relatively straight forward. I'd do it something like this:
add_action( 'wp_head', 'display_analytics_by_page', 1 );
function display_analytics_by_page(){
// Default Script Code with individual UA codes replaced
$script = '<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=[UA-CODE]"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag(\'js\', new Date());
gtag(\'config\', \'[UA-CODE]\');
</script>';
// Array of UA codes by state
$codes = array(
'Alabama' => 'UA-123456789-1',
'Oregon' => 'UA-987654542-3',
'Vermont' => 'UA-000000000-0'
);
// Get title of this page
$title = get_the_title();
// If this page title exists in the codes array, swap placeholder and echo it.
if( isset($codes[$title]) ){
echo str_replace( '[UA-CODE]', $codes[$title], $script );
}
}
I commented along the way, but the gist is to put in the "default" script, but pull out the UA code. This will only work if you need the same exact script code in each one, otherwise you'll have to add each script to the $codes array instead.
Then create an array of the UA Codes (or full scripts if needed), keyed by the page title.
Then check the page title, and if that exists, pull that code in and echo it. This is run on the wp_head hook, so you just need to put this code in your functions.php (or similar) file.
If you want to go easy with no-coding, then go with a plugin. Jump to Plugins > Add New and Search for Google Analytics in the search box. Install the plugin named Google Analytics for WordPress (Formerly GADWP). Activate and connect the plugin with your Google Analytics property. When all is done, you will see a new tab beside your post's title. See a screenshot here.
And if you want the net analytics for the whole web site then head to your admin dashboard. A new widget will appear there with the analytics.
Documentation for the plugin can be found here.
I hope it helps.
I'm curious why you need a separate GA account for all the locations? Common practice in this scenario would be:
Use 1 account
Create 1 GA view for the entire domain
Create +1 view for each location by filtering traffic based on the URL
If the different accounts are related to limiting user access, know that you can grant user access based on each property view.

How can I override the exisiting Schema.org markup from Yoast using GTM?

I've configured my GTM with the JSON-LD markup I placed in GTM and its firing perfectly. However, if I will check it in structured data testing tool still the auto-generated markup by Yoast is showing.
Can I just remove or disable the Yoast schema? Will it not be harmful in terms of SEO?
To answer the first question, you can remove all the Yoast schema by adding the following to your functions.php (should be in your child theme):
function bybe_remove_yoast_json($data){
$data = array();
return $data;
}
add_filter('wpseo_json_ld_output', 'bybe_remove_yoast_json', 10, 1);
Tested working and per: https://www.bybe.net/yoast-seo-guide-disable-schema-json-ld-wordpress/
There's no harm in what Yoast is adding. You could leave it there. Or you could devise some JavaScript to find the script tag and remove it.

How can I successfully use browser-sync with wordpress locally?

I'm trying to get browser-sync to work with my multipress wordpress install, for simpler mobile / responsive development.
Currently I'm having problems in that, my normal development takes place at local.example.com, and browser-sync is proxying this (via 123.456.78.9:3202, as per browser sync).
So far browser-sync loads the site, but none of my scripts or CSS are loading (although images load fine). They jsut fail with no response in the network panel.
I'm using NGINX for hosting the site, as opposed to apache.
Does anyone have any wordpress browser-sync experience? Am I missing something with the browser-sync set up? And tips for this would be super welcome. I'd love to get this as a solid part of my work flow.
The problem is to do with how wordpress handles URLs, in that it normally uses full URLs for including content and links etc.
The proxy is trying to access these on another domain and that's why it's failing.
Update
A much simple, cleaner and maintainable strategy, that also helps with development environments is to use the Root Relative URLs plugin. Adds hooks and configs similar to below, but also updates your content and editors to apply the same structure, so it's a bit more robust
Original Answer
You can add a simple hook (source: wordpress relative urls) to filter wordpress generated urls and remove the base domain so you get relative links to styles and posts etc:
$relative_url_filters = array(
'script_loader_src', //js
'style_loader_src', //css
'post_link', // Normal post link
'post_type_link', // Custom post type link
'page_link', // Page link
'attachment_link', // Attachment link
'get_shortlink', // Shortlink
'post_type_archive_link', // Post type archive link
'get_pagenum_link', // Paginated link
'get_comments_pagenum_link', // Paginated comment link
'term_link', // Term link, including category, tag
'search_link', // Search link
'day_link', // Date archive link
'month_link',
'year_link'
);
foreach ( $relative_url_filters as $relative_url_filters ) {
add_filter( $relative_url_filters, 'wp_make_link_relative' );
}
Which should clean up most of your issues and get browser-sync working nicely.
I'm still having some issues where I have more complex inclusions for images, but more or less it's working and we're already seeing how cool it is!

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.

How to set nofollow rel attribute to all outbound links in WordPress? Any Plugin?

I want to know how to automatically set all links to nofollow in Wordpress. Is there a WP Plugin that will make all my outbound links nofollow?
Help is greatly appreciated!
If you are make this change for SEO optimization, you can't make the change only with JS because the google bots don't read the content generated by Javascript.
But, you can add a filter in your function.php like this:
function rel_nofollow( $content ) {
return preg_replace_callback( '/<a[^>]+/', 'rel_nofollow_callback', $content );
}
add_filter( 'the_content', 'rel_nofollow', 99999 );
function rel_nofollow_callback( $matches ) {
$link = $matches[0];
$exclude = '('. home_url() .'|http://([^.]+\.)?(wp.org|wp.com))';
if ( preg_match( '#href=\S('. $exclude .')#i', $link ) )
return $link;
if ( strpos( $link, 'rel=' ) === false ) {
$link = preg_replace( '/(?<=<a\s)/', 'rel="nofollow" ', $link );
} elseif ( preg_match( '#rel=\S(?!nofollow)#i', $link ) ) {
$link = preg_replace( '#(?<=rel=.)#', 'nofollow ', $link );
}
return $link;
}
This function set all links into the post to the attribute: rel="nofollow", but, if you want change all the site maybe you must try with this plugin
A number of years later, the details changed but the question remains.
For one thing, the number of relevant rel attributes has grown:
nofollow alternatives sponsored and ugc
noopener, strongly suggested for security
noreferrer, less relevant with modern browser versions
external, XHTML valid, link to an external (different) site; not nofollow nor target="_blank", so dubious utility
somewhat related noindex
Disregard numerous examples in older posts of code snippets to tune rel= attributes, as simply hacking WordPress PHP is quite undesirable these days. With frequent and (optionally) automated core software and plugin updates, and with security plugins checking all the code for non-standard mods, let's focus on the UI and plugin configuration methods instead.
While the Classic editor gives an option to Open link in a new tab, current version of the Gutenberg editor in combination with Yoast also provides UI to select nofollow or sponsored.
For more controls there are plugins. The one mentioned in earlier answers is still around, named External Links and with 80K installs and an exclusive focus on the link attributes, plus link icons and WPMU.
A much more popular plugin, with 2M+ installs is All in One SEO (AIOSEO), which among many other features provides access to noindex and nofollow.
Perhaps the most popular among SEO plugins, with 5M+ installs is Yoast SEO, but current version provides no additional help with bulk nofollow, though it adds noopener, as documented, but apparently also noreferrer to external links automatically.
Discussion so far related to external links, as nofollow or noopener are not used for internal links. Instead, concerns about duplicate content or low quality (thin content) pages raise questions about which parts of the site navigation and interlinking to index. Yoast shines here, with fine grain support for indexing author, tag or category links and pages.
Beyond search engine interpretation of individual links, rel=canonical tag allows merging together treatment of multiple internal links that actually lead to the same page or post. We are only guessing how Google interprets our 'hints' about links and hope that Yoast and WordPress produce a structure that is digestible.
Whether a particular subset of the rel and SEO plugins mentioned, in combination with a particular version of your favorite editor can work reliably alongside each other, and how to sequence their combined workflow is entirely TBD. A safe and consistent way of iteratively making specific adjustments to subsets of external and groupings of internal links, with a special treatment of affiliate and associate links is TBD. How to tackle a substantial site already in production, and retroactively apply select auto-magical adjustments is TBD. Any detailed suggestions, links to specific information and best of all, actual experiences would be rather welcome.
How browsers and spiders actually traverse a WordPress site is controlled at a different system level. The popular plugin for HTTP redirection is conveniently called Redirection. URL rewriting in Apache web server is configured via .htaccess file. cPanel and several system plugins, e.g. Really Simple SSL or WordFence, have automation in their UI for some of the settings, though conflicts may need to be resolved manually. These subjects are best covered in depth elsewhere.
For coding affectionados, two earlier attempts at different approaches:
Much tighter jQuery implementation, compared with the one below.
Really old direct hack of the entire page HTML, fetched from DOM.
Within WordPress you can select to open a link in a new window. When this is selected WordPress adds an attribute target="_blank". This is what I usually do with outbound links. If so you can use jQuery to add the attribute rel="nofollow" like this
<script type="text/javascript">
$(document).ready(function() {
$('a[target="_blank"]').attr('rel', 'nofollow');
});
</script>

Resources