phpfunction

Define metadescription


I have the following code that creates the meta-description. I'm getting a 0 as meta-description when trying to add a text after the $info['desc'].

The original code is

function apply_meta($info) {
if (isset($info['desc']) && !empty($info['desc'])) {
    define('META_DESC', $info['desc']);
}

What I did is :

function apply_meta($info) {
if (isset($info['desc']) && !empty($info['desc'])) {
    define('META_DESC', $info['desc'] + 'my text. Read more about ' + $info['desc'] );
}

Solution

  • Period (.) is used in PHP to concat the strings. Replace your + sign with period like this:

    function apply_meta($info) {
    if (isset($info['desc']) && !empty($info['desc'])) {
        define('META_DESC', $info['desc'] . 'my text. Read more about ' . $info['desc'] );
    }