Home > Software engineering >  Fatal error: Cannot redeclare add_theme_support()
Fatal error: Cannot redeclare add_theme_support()

Time:08-20

I have a directory and file like this

folders

functions.php

<?php
if (function_exists('add_theme_support')) {
    add_theme_support('post-thumbnails');
}
function add_theme_support() {
    wp_enqueue_style('bootstrap', get_template_directory_uri().'/bootstrap/css/bootstrap.rtl.min.css');
    wp_enqueue_style('bootstrap', get_template_directory_uri().'/style.css');
    wp_enqueue_script('bootstrap', get_template_directory_uri().'/bootstrap/js/bootstrap.min.js');
}
add_action('wp_enqueue_scripts', 'add_theme_scripts');

I get this error

Fatal error: Cannot redeclare add_theme_support() (previously declared in C:\xampp\htdocs\projects\cms\wordpress\wp-includes\theme.php:2576) in C:\xampp\htdocs\projects\cms\wordpress\wp-content\themes\oxbir\functions.php on line 5

CodePudding user response:

As the error says, the function has already been defined. You need to check with if before function. Edit as below.

if(!function_exists('add_theme_support')) {
  function add_theme_support() {
    ....
  }
}
  • Related