I am having an issue with this shortcode plugin.. Warning: Illegal string offset ‘title’

The answer here is assumed the user equipped with the following knowledge

  • PHP and know how to find reference from php manual online
  • WP built-in shortcode_atts() – Combine user attributes with known attributes and fill in defaults when needed.

I guess you haven’t written the shortcode in a proper form.

Illegal string offset ‘title’ means $atts[‘title’] does not exist.
It does not exist because when shortcode is being called, title is not given

To resolve this, you need to set default values and then combine it with user attributes(the attributes supply when anyone call the shortcode).

Here is a recommended writing style for a shortcode

add_shortcode( 'recent-blogs', 'cp_sidebar_recent_blogs_shortcode');
function cp_sidebar_recent_blogs_shortcode( $atts, $content = null ) {

    // the following is default value + merge value from shortcode calling, 
    // it can prevent errors in case any attribute is empty such as title is not defined
    extract(shortcode_atts(array(
        'title' => '',
        'layout' => '',
    ), $attr));

    // with extract() you don't need to explicitly create a $title_default
    // because extract() will create $title with value ''

    if ( $atts['title'] == 'Related Posts' && $atts['layout'] == 'horizontal' ) {
        $title="Related Posts";
    }
    else {
        $title="Recent Posts";
    }

    // ... your other code continue
}