• Resolved IdeFixx

    (@idefixx)


    Hello.

    I ran into an issue with the shortcode inserted in Twenty Twenty-Three theme. This shortcode block works fine in the theme part:

    [post_coauthors]

    Here is its code from the child’s theme functions.php:

    add_shortcode( 'post_coauthors', 'myshortcode_coauthor' );
    function myshortcode_coauthor() {
    return coauthors_links();
    }

    But it also breaks the structure of an HTML document:

    <html>
    <head></head> - empty
    <body>
    <a>author's name and link</a> - first time here
    <meta> - all header tags are here
    <main>
    <div class="wp-block-group">
    <a>author's name and link</a> - secondly here

    As you can see:

    1. HTML head content is shifted to <body>
    2. Content of the shortcode is displayed twice

    Even if I try to disable all other plugins it does not help. The HTML structure is still broken. Co-Authors Plus Troubleshooting Mode does not help either, it just activates parent theme without the shortcode.

    I’ll be glad for any suggestions or ideas on how can I fix it. Thank you.

    WP Version 6.3.1
    Co-Authors Plus Version 3.5.15
    Twenty Twenty-Three Version: 1.2

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter IdeFixx

    (@idefixx)

    Probably it’s related to this pull request https://github.com/Automattic/Co-Authors-Plus/pull/997

    Plugin Contributor Gary Jones

    (@garyj)

    That PR hasn’t been merged yet, so unless you’re running that PR’s branch (unlikely), then it’s not that.

    The default behaviour of the coauthors_links() function is to echo immediately, which doesn’t work for what you need with shortcodes.

    Try:

    add_shortcode( 'post_coauthors', 'myshortcode_coauthor' );
    function myshortcode_coauthor() {
        return coauthors_links(null, null, null, null, false);
    }
    Thread Starter IdeFixx

    (@idefixx)

    Thank you very much for your help. Your shortcode works.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Shortcode breaks HTML’ is closed to new replies.