Cheko García
Cheko García

Reputation: 59

functions.php code is printed on screen wordpress

I'm trying to make a child theme and everything looked ok untill I changed php version from 5.6 to 7.2.1, what is happening is that functions.php code is printed (echoed) on the screen, check the image out, if I'm not making sense.

This is the very top of my home page

This is my functions.php, which is only an example from wordpress to show you whats happening:

<?function wporg_shortcode($atts = [], $content = null, $tag = '')
{
    // normalize attribute keys, lowercase
    $atts = array_change_key_case((array)$atts, CASE_LOWER);

    // override default attributes with user attributes
    $wporg_atts = shortcode_atts([
         "title" => "WordPress.org",
     ], $atts, $tag);

    // start output
    $o = '';

    // start box
    $o .= '<div class="wporg-box">';

    // title
    $o .= '<h2>' . esc_html__($wporg_atts['title'], 'wporg') . '</h2>';

    // enclosing tags
    if (!is_null($content)) {
        // secure output by executing the_content filter hook on $content
        $o .= apply_filters('the_content', $content);

        // run shortcode parser recursively
        $o .= do_shortcode($content);
    }

    // end box
    $o .= '</div>';

    // return output
    return $o;
}

function wporg_shortcodes_init()
{
    add_shortcode('wporg', 'wporg_shortcode');
}

add_action('init', 'wporg_shortcodes_init');

Upvotes: 1

Views: 963

Answers (3)

Faisal Shehzad
Faisal Shehzad

Reputation: 3

Simply apply basic php tag at start and end.

Upvotes: 0

Madhur
Madhur

Reputation: 1772

Some times Wordpress doesn't detect short tags <? ?> in Php due to changing the version from 5.6 to 7.0. So you need to start <?php enclosing with the ?>

Upvotes: 1

Nikita Leshchev
Nikita Leshchev

Reputation: 1844

Start file from <?php not from <?

Upvotes: 2

Related Questions