Custom canonical?

I have a plugin that creates a directory beneath a page. There are custom rewrites involved.

For example:

/pagename
/pagename/dir/category/detail

but in all of the "child" pages which are created by my plugin the canonical always shows the page they are tied to so the canonical is always /pagename instead of /pagename/dir/category etc....

How can I hack this canonical generator so that if the url is /pagename/dir/etc..... it will add on the rest of the request url?

  • jpwdesigns
    • Design Lord, Child of Thor

    Here are my rewrites:

    add_rewrite_tag('%d_category%','([^&]+)');
    add_rewrite_tag('%tr_category%','([^&]+)');
    add_rewrite_tag('%profile%','([^&]+)');
    
    add_rewrite_rule('^find-a-designer/asid/([^/]+)/?$','index.php?pagename=find-a-designer&d_category=$matches[1]','top');
    add_rewrite_rule('^find-a-designer/asid/([^/]*)/([^/]*)/?','index.php?pagename=find-a-designer&d_category=$matches[1]&profile=$matches[2]','top');
    add_rewrite_rule('^industry-partners/asid/([^/]+)/?$','index.php?pagename=industry-partners&tr_category=$matches[1]','top');
    add_rewrite_rule('^industry-partners/asid/([^/]*)/([^/]*)/?','index.php?pagename=industry-partners&tr_category=$matches[1]&profile=$matches[2]','top');
    add_rewrite_rule('^students/asid/([^/]+)/?$','index.php?pagename=students&profile=$matches[1]','top');

    I think if i hacked the plugin page wds-onpage.php wds_head() function line 145
    what if I added something like this:

    if ($wp_query->query_vars['d_category']) {
         echo "\t".'<link rel="canonical" href="'.get_page_link( $page_data->id).'asid/'.$wp_query->query_vars['d_category'].'/" />'."\n";
    } else .....
  • jpwdesigns
    • Design Lord, Child of Thor

    WPMU DEV SEO works great. Everything is displayed both on front end and admin but when i have Events Manager activated, and try to visit the Events calendar page it pulls up blank. IF I then disable WPMU DEV SEO and visit calendar page it works. Since I have to use the events manager I can not use WPMU DEV SEO. I posted a thread about it both here and with Events Manager but don't have a solution yet.

  • Philip John
    • DEV MAN’s Apprentice

    Hmm okay.

    I've not managed to replicate this so here are some questions and things to try;
    - what version of WordPress are you using?
    - does it work when you use the default WP theme?
    - does it work if you disable all plugins except SEO and Events Manager?
    - is this on a single site or multisite?
    - if multisite is it the main site or sub-site
    - if multisite do you have the plugins per-site or network activated?

    Those should help to get to the bottom of the cause...

    Phil

  • Philip John
    • DEV MAN’s Apprentice

    Hiya,

    As we haven't heard back from you we're going to assume the problem was sorted out and mark this ticket as resolved.

    If it wasn't resolved, or you have any more questions related to this thread please feel free to post them below and tick the 'Mark as Not Resolved (re-open)' box below the post area (or else we'll miss it!)

    Otherwise, thanks for using the forums, and for being a member of WPMU DEV, it's a pleasure to help you out and we look forward to being of assistance in the future.

    Thanks!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.