Can you provide a link to a page which shows this issue? We placed a canonical in the back end of this page: https://youngnaturistsamerica.com/labiaplasty-young-girls-vagina-labia-body-modification-part-two/ pointing it here: https://youngnaturistsamerica.com/labiaplasty-new-vagina-cosmetic-surgery-trend-for-girls/ (and it doesn't appear in source code)
I just checked your website. I saw following in HTML source:
URL .../feminism-womens-issues/page/2/:
<!-- This site is optimized with the Yoast SEO plugin v4.0.2 - https://yoast.com/wordpress/plugins/seo/ -->
<title> .... 2</title>
<meta name="description" content="..."/>
<meta name="robots" content="noindex,follow,noodp"/>
<meta name="keywords" content="..."/>
<link rel="prev" href=".../feminism-womens-issues/" />
<link rel="next" href=".../feminism-womens-issues/page/3/" />
I don't see canonical and og:url tags. It's weird and it seems as conflict with some plugin or the theme. You can see that exists next and prev URLs.
I see that sitemap doesn't contain first URL (where you have manually set canonical URL) which works as should.
I'm copying message related to plugin conflicts:
_Sometimes strange behavior may be caused by a plugin or theme conflict. The fastest way to rule out conflicts is to deactivate all non-Yoast plugins and switch to a standard theme like Twenty Sixteen. If this resolves the issue, you have a conflict and should activate one plugin at a time until you locate the conflict. Finally, after all plugins are active, switch to your theme. This will narrow down the conflict to a specific plugin or a theme conflict._
_If you are unfamiliar with checking for conflicts, we wrote a small guide that will walk you through the steps. You can find it here: https://kb.yoast.com/kb/how-to-check-for-plugin-conflicts/_
_We understand if you wouldn't want to deactivate your plugins and switch themes on a production site, so it may be preferable that you set up a staging environment for your tests._
_If you're not familiar with a staging site, this article will help you get started: http://www.wpbeginner.com/wp-tutorials/how-to-create-staging-environment-for-a-wordpress-site/_
_Can you please inform us of the results?_
We did as suggested with testing for conflicts, but came up with nothing... :( So what do you suggest?
I can reproduce your issue if I add following code:
add_filter( 'wpseo_opengraph_url', '__return_false' );
add_filter( 'wpseo_canonical', '__return_false' );
Basically, I can't see your code and it's hard to find this. Also, I don't know your versions of WP, PHP and other plugins. I see that you have customized theme.
The best which I can suggest is to you create PHP script (eg. canonical-test.php) with following content:
<?php
// require wordpress
define('DOING_AJAX', false);
define('WP_USE_THEMES', true);
define('QM_DISABLED', true);
define('DONOTCACHEPAGE', true);
define('WP_DEBUG', true);
define('WP_DEBUG_DISPLAY', true);
define('WP_DEBUG_LOG', false);
$_SERVER['REQUEST_URI'] = '/';
$_SERVER['REQUEST_METHOD'] = 'GET';
// Load the WordPress library.
require_once( dirname(__FILE__) . '/wp-load.php' );
// Set up the WordPress query.
wp();
// basic init for templates
do_action( 'template_redirect' );
echo '<pre>';
global $wp_filter;
echo "Debug info for filters\n";
if ( isset( $wp_filter['wpseo_canonical'] ) ) {
var_dump( $wp_filter['wpseo_canonical'] );
}
echo "Try to init Yoast\n";
$wpseo_front=WPSEO_Frontend::get_instance();
$wpseo_front->front_page_specific_init();
echo "Test Yoast API\n";
echo "Canonical URL\n";
$url = $wpseo_front->canonical( false, true, true );
var_dump( $url );
echo '</pre>';
Upload it in your root directory (where is index.php, wp-load.php,...), Then try to run this script by typing http://....../canonical-test.php It shows debug info for wpseo_canonical hook (possible root of this issue) and then try to run canonical with $no_override = true which shows URL regardless previous filter.
PS. I don't know your knowledge of PHP, FTP,... Maybe it's too complex test. You can install Query monitor or debug objects (it doesn't work on WP 4.7) for more debugging.
I want to apologize for not getting back to you any sooner, @youngnaturists. Unfortunately we cannot reproduce this issue.
If I understand correctly you've checked for a plugin conflict. Did you check for a theme conflict as well? As this is such a specific issue and we're not sure if this bug could be present on other people's sites, please check this article we've written about writing a bug report.
Please let us know if the issue still persists with a theme such as twentysixteen or twentyseventeen.
Closing due to inactivity. If this issue is still relevant, please respond with requested information.
Just wanted to contribute here, because this is relatively high on the google search results, and while hopefully @youngnaturists has resolved this issue, I'm hoping to help people with the same issue in the future.
Before checking for plugin and theme conflicts, please simply check whether the setting Discourage search engines from indexing this site under Settings > Reading is checked. If it is checked, you will likely see <meta name="robots" content="noindex,follow"> in your site's header, and it seems that there will be no canonical url set by Yoast SEO.
I am seeing this on one of my sites, too—on my local test site and on the corresponding online test site (copied with Duplicator). Other websites (same version of WordPress and Yoast SEO) are fine, on the same local machine, too.
A bespoke theme as well as twentyseventeen are affected.
It does work fine (canonical shown) with all plugins activated, until I activate Yoast—that makes the canonical disappear (only on this one site).
I have diffed all the Yoast files against the ones of another working site—all of them are identical!
Also optimized the database with WP-Optimize (just for good measure).
So I don't know what to try next …
WordPress 4.9.8
Yoast SEO 8.2
The script from @stodorovic does show the canonical:
Debug info for filters
Try to init Yoast
Test Yoast API
Canonical URL
string(21) "https://example.test/"
Most helpful comment
Just wanted to contribute here, because this is relatively high on the google search results, and while hopefully @youngnaturists has resolved this issue, I'm hoping to help people with the same issue in the future.
Before checking for plugin and theme conflicts, please simply check whether the setting Discourage search engines from indexing this site under Settings > Reading is checked. If it is checked, you will likely see
<meta name="robots" content="noindex,follow">in your site's header, and it seems that there will be no canonical url set by Yoast SEO.