Search code examples
phpwordpresspluginssyntax-errorparse-error

Parse error: syntax error, unexpected (in WP plugin) PHP


I'm trying to add a button Read more, but when adding a button code in DIV, an error appears, and the plugin does not work. Tell me where the error is?

Parse error: syntax error, unexpected 'href' (T_STRING) in /****/public_html/wp-content/plugins/page-list/page-list.php on line 351

/*BEFORE */
$list_pages_html .= '<div class="page-list-ext-item-content">'.$content.';                  

/*AFTER */
$list_pages_html .= '<div class="page-list-ext-item-content">'.$content.<p><a href="'.$link.'" title="'.esc_attr($page- rel="nofollow">post_title).'">Read More</a></p>'</div>';

Thanks!


Solution

  • There are a couple of things wrong with your code. The /*BEFORE */ code is broken because of that ' at the end, but you want to get the /*AFTER */ code working so let's focus on that:

    $list_pages_html .= '<div class="page-list-ext-item-content">'.$content.<p>
    // missing a ' here: --------------------------------------------------^^
    
    <a href="'.$link.'" title="'.esc_attr($page- rel="nofollow">post_title).'">Read
    // this doesn't belong here: ---------------^^^^^^^^^^^^^^^
    
     More</a></p>'</div>';
    // Why is ---^ that ' there?
    

    I think what you're looking for is this:

    $list_pages_html .= '<div class="page-list-ext-item-content">'.$content.'<p><a href="'.$link.'" title="'.esc_attr($page->post_title).'" rel="nofollow">Read More</a></p></div>';