I have a php function with a shortcode to add share buttons, but I’m having an error!

This is happening because in the function the first parameter is named $content and you use it as HTML content:

function add_social_share_buttons($content) {
....
    // Append the share buttons HTML to the content
    $content .= $share_buttons;

    return $content;
}

But the first parameter of a shortcode callback is not a string of content, it’s an array of attributes:

https://developer.wordpress.org/reference/functions/add_shortcode/

It should instead look more like this:

function add_social_share_buttons( $attributes, string $content="", string $shortcode ): string {

Where:

[$shortcode $attributes]$content[/$shortcode]

Note the addition of PHP type hinting, and note that $attributes is sometimes an array, and sometimes it’s an empty string, be sure to set default values using the shortcode_atts function:

https://developer.wordpress.org/reference/functions/shortcode_atts/

Also consider building a custom block for this instead using a PHP rendered block rather than JS for a similar experience.

tech