Wordpress function.php Error [duplicate] - php

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
ive been working on my wordpress website source code, when I try to reload the page I get this error:
Parse error: syntax error, unexpected end of file in /home3/snesni/public_html/wp-content/themes/Activello-master/functions.php
on line 284
My function.php line 284-285 says:
endif; // activello_woo_setup add_action( 'after_setup_theme', 'activello_woo_setup' );
And I cant seem to change WP theme. Not sure what to do.
Below is the function.php.
<?php
/**
* activello functions and definitions
*
* #package activello
*/
/**
* Set the content width based on the theme's design and stylesheet.
*/
if ( ! isset( $content_width ) ) {
$content_width = 1090; /* pixels */
}
/**
* Set the content width for full width pages with no sidebar.
*/
function activello_content_width() {
if ( is_page_template( 'page-fullwidth.php' ) ) {
global $content_width;
$content_width = 1008; /* pixels */
}
}
add_action( 'template_redirect', 'activello_content_width' );
if ( ! function_exists( 'activello_main_content_bootstrap_classes' ) ) :
/**
* Add Bootstrap classes to the main-content-area wrapper.
*/
function activello_main_content_bootstrap_classes() {
if ( is_page_template( 'page-fullwidth.php' ) ) {
return 'col-sm-12 col-md-12';
}
return 'col-sm-12 col-md-8';
}
endif; // activello_main_content_bootstrap_classes
if ( ! function_exists( 'activello_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function activello_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
*/
load_theme_textdomain( 'activello', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/**
* Enable support for Post Thumbnails on posts and pages.
*
* #link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
add_theme_support( 'post-thumbnails' );
add_image_size( 'activello-featured', 1170, 550, true );
add_image_size( 'activello-slider', 1920, 550, true );
add_image_size( 'activello-thumbnail', 330, 220, true );
add_image_size( 'activello-medium', 640, 480, true );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => esc_html__( 'Primary Menu', 'activello' )
) );
// Enable support for Post Formats.
add_theme_support( 'post-formats', array(
'video',
'audio',
) );
// Setup the WordPress core custom background feature.
add_theme_support( 'custom-background', apply_filters( 'activello_custom_background_args', array(
'default-color' => 'FFFFFF',
'default-image' => '',
) ) );
// Enable support for HTML5 markup.
add_theme_support( 'html5', array(
'comment-list',
'search-form',
'comment-form',
'gallery',
'caption',
) );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
}
endif; // activello_setup
add_action( 'after_setup_theme', 'activello_setup' );
/**
* Register widgetized area and update sidebar with default widgets.
*/
function activello_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'activello' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
));
register_widget( 'activello_social_widget' );
register_widget( 'activello_recent_posts' );
register_widget( 'activello_categories' );
register_widget( 'activello_instagram_widget' );
}
add_action( 'widgets_init', 'activello_widgets_init' );
/* --------------------------------------------------------------
Theme Widgets
-------------------------------------------------------------- */
require_once(get_template_directory() . '/inc/widgets/widget-categories.php');
require_once(get_template_directory() . '/inc/widgets/widget-social.php');
require_once(get_template_directory() . '/inc/widgets/widget-recent-posts.php');
require_once(get_template_directory() . '/inc/widgets/widget-instagram.php');
/**
* This function removes inline styles set by WordPress gallery.
*/
function activello_remove_gallery_css( $css ) {
return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
}
add_filter( 'gallery_style', 'activello_remove_gallery_css' );
/**
* Enqueue scripts and styles.
*/
function activello_scripts() {
// Add Bootstrap default CSS
wp_enqueue_style( 'activello-bootstrap', get_template_directory_uri() . '/inc/css/bootstrap.min.css' );
// Add Font Awesome stylesheet
wp_enqueue_style( 'activello-icons', get_template_directory_uri().'/inc/css/font-awesome.min.css' );
// Add Google Fonts
wp_enqueue_style( 'activello-fonts', '//fonts.googleapis.com/css?family=Lora:400,400italic,700,700italic|Montserrat:400,700|Maven+Pro:400,700');
// Add slider CSS only if is front page ans slider is enabled
if( ( is_home() || is_front_page() ) && get_theme_mod('activello_featured_hide') == 1 ) {
wp_enqueue_style( 'flexslider-css', get_template_directory_uri().'/inc/css/flexslider.css' );
}
// Add main theme stylesheet
wp_enqueue_style( 'activello-style', get_stylesheet_uri() );
// Add Modernizr for better HTML5 and CSS3 support
wp_enqueue_script('activello-modernizr', get_template_directory_uri().'/inc/js/modernizr.min.js', array('jquery') );
// Add Bootstrap default JS
wp_enqueue_script('activello-bootstrapjs', get_template_directory_uri().'/inc/js/bootstrap.min.js', array('jquery') );
// Add slider JS only if is front page ans slider is enabled
if( ( is_home() || is_front_page() ) && get_theme_mod('activello_featured_hide') == 1 ) {
wp_register_script( 'flexslider-js', get_template_directory_uri() . '/inc/js/flexslider.min.js', array('jquery'), '20140222', true );
}
// Main theme related functions
wp_enqueue_script( 'activello-functions', get_template_directory_uri() . '/inc/js/functions.min.js', array('jquery') );
// This one is for accessibility
wp_enqueue_script( 'activello-skip-link-focus-fix', get_template_directory_uri() . '/inc/js/skip-link-focus-fix.js', array(), '20140222', true );
// Add instafeed/instagram
if( is_active_widget( false, false, 'activello-instagram', true ) ){
wp_enqueue_script('activello-instafeedjs', get_template_directory_uri().'/inc/js/instafeed.min.js', array('jquery') );
}
// Threaded comments
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'activello_scripts' );
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/inc/extras.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
require get_template_directory() . '/inc/jetpack.php';
/**
* Load custom nav walker
*/
require get_template_directory() . '/inc/navwalker.php';
/**
* Load custom metabox
*/
require get_template_directory() . '/inc/metaboxes.php';
/**
* Social Nav Menu
*/
require get_template_directory() . '/inc/socialnav.php';
/* Globals */
global $site_layout, $header_show;
$site_layout = array('pull-right' => esc_html__('Left Sidebar','activello'), 'side-right' => esc_html__('Right Sidebar','activello'), 'no-sidebar' => esc_html__('No Sidebar','activello'),'full-width' => esc_html__('Full Width', 'activello'));
$header_show = array(
'logo-only' => __('Logo Only', 'travelify'),
'logo-text' => __('Logo + Tagline', 'travelify'),
'title-only' => __('Title Only', 'travelify'),
'title-text' => __('Title + Tagline', 'travelify')
);
/* Get Single Post Category */
function get_single_category($post_id){
if( !$post_id )
return '';
$post_categories = wp_get_post_categories( $post_id );
if( !empty( $post_categories ) ){
return wp_list_categories('echo=0&title_li=&show_count=0&include='.$post_categories[0]);
}
return '';
}
// Change what's hidden by default
add_filter('default_hidden_meta_boxes', 'be_hidden_meta_boxes', 10, 2);
function be_hidden_meta_boxes($hidden, $screen) {
if ( 'post' == $screen->base || 'page' == $screen->base ) {
// removed 'postexcerpt',
$hidden = array(
'slugdiv',
'trackbacksdiv',
'postcustom',
'commentstatusdiv',
'commentsdiv',
'authordiv',
'revisionsdiv'
);
}
return $hidden;
}
if ( ! function_exists( 'activello_woo_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*/
function activello_woo_setup() {
/*
* Enable support for WooCemmerce.
*/
add_theme_support( 'woocommerce' );
}
endif; // activello_woo_setup
add_action( 'after_setup_theme', 'activello_woo_setup' );

Did you try to use regular if wrapping?
/**
* Sets up theme defaults and registers support for various WordPress features.
*/
add_action( 'after_setup_theme', 'activello_woo_setup' );
if ( !function_exists( 'activello_woo_setup' ) ){
function activello_woo_setup() {
/* Enable support for WooCommerce. */
add_theme_support( 'woocommerce' );
}
}
Doubt it would make any difference, but you never know...

on line 281 : if ( ! function_exists( 'activello_woo_setup' ) ) {
replace : if ( !function_exists( 'activello_woo_setup' ) ) {

Related

WordPress - functions.php causing WordPress error

I have the following folder structure for my theme:
theme
inc
theme
functions.php
init.php
functions.php
In inc/theme/functions.php, I'm placing all theme specific functions (i.e. removing taxonomies etc). In theme/functions.php, I have all my core functions.
With my current code, WordPress states "The site is experiencing technical difficulties.". If I delete everything in theme/functions.php, the content loads, but the code in inc/theme/functions.php is not being executed. For example, in inc/theme/functions.php, I have wp_enqueue_style( 'style', get_stylesheet_uri() ); and none of the styles are pulling through.
Can't seem to figure out:
Why theme/functions.php is causing a WordPress error.
Why inc/theme/functions.php is not being executed.
theme/functions.php
<?php
require_once trailingslashit( get_template_directory() ) . 'inc/init.php';
new theme_ThemeFunctions;
class theme_ThemeFunctions {
function __construct() {
load_theme_textdomain( 'theme' );
add_action( 'init', array( $this, 'post_types_taxonomies' ) );
add_action( 'init', array( $this, 'register_menus' ) );
}
public function post_types_taxonomies() {
register_post_type(
'case-studies',
build_post_args(
'case-study', 'Case study', 'Case studies',
array(
'menu_icon' => 'dashicons-book',
'menu_position' => 20,
'has_archive' => true
)
)
);
}
public function register_menus() {
register_nav_menus(
array(
'main' => __( 'Main Menu', 'theme' ),
)
);
}
}
?>
inc/theme/functions.php
<?php
function scriptAndStyles() {
wp_enqueue_style( 'style', get_stylesheet_uri() );
}
add_action( 'wp_enqueue_scripts', 'scriptAndStyles' );
function remove_editor() {
remove_post_type_support('page', 'editor');
}
add_action('admin_init', 'remove_editor');
// Remove featured image option from pages
function remove_thumbnail_box() {
remove_meta_box( 'postimagediv','page', 'side' );
}
add_action('do_meta_boxes', 'remove_thumbnail_box');
// Remove posts type option
function post_remove () {
remove_menu_page('edit.php');
}
add_action('admin_menu', 'post_remove');
?>
inc/init.php
<?php
$include_dir = trailingslashit( get_template_directory() ) . 'inc/';
// Load any custom functions
require_once $include_dir . 'theme/functions.php';
?>
You need use get_template_directory() for require your files.
And use new theme_ThemeFunctions below class itself.
Also use to view errors:
define('WP_DEBUG', 1);
define('WP_DEBUG_DISPLAY', 1);

Include custom template file issue in Woocommerce my account page

I am trying to add an include a template file located in my active child theme:
childtheme/woocommerce/myaccount/order-a-kit.php
The function use also echo "Hello World" which is displayed successfully, but not the included php template file.
I have tried those:
include($_SERVER['DOCUMENT_ROOT']."twentyseventeen-child/woocommerce/myaccount/order-a-kit.php");
include($get_stylesheet_directory_uri()."twentyseventeen-child/woocommerce/myaccount/order-a-kit.php");
include 'twentyseventeen-child/woocommerce/myaccount/order-a-kit.php';
The content of the order-a-kit.php is super simple, I am just trying to include that file:
<?php
?>
<div>
<p>
Look at me
</p>
</div>
This is my function.php section and everything is doing as it should except the include function towards the bottom:
add_filter( 'woocommerce_account_menu_items', 'add_my_menu_items', 99, 1 );
function add_my_menu_items( $items ) {
$my_items = array(
// endpoint => label
'order-a-kit' => __( 'Order A Kit', 'woocommerce'),
'orders' => __( 'Order History', 'my_plugin' ),
);
$my_items = array_slice( $items, 0, 1, true ) +
$my_items +
array_slice( $items, 1, count( $items ), true );
return $my_items;
}
//adding custom endpoint
function my_custom_endpoints() {
add_rewrite_endpoint( 'order-a-kit', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'my_custom_endpoints' );
function my_custom_query_vars( $vars ) {
$vars[] = 'order-a-kit';
return $vars;
}
add_filter( 'query_vars', 'my_custom_query_vars', 0 );
function my_custom_flush_rewrite_rules() {
flush_rewrite_rules();
}
add_action( 'wp_loaded', 'my_custom_flush_rewrite_rules' );
//including custom endpoint
function my_custom_endpoint_content() {
include 'twentyseventeen-child/woocommerce/myaccount/order-a-kit.php';
echo '<p>Hello World!</p>';
}
add_action( 'woocommerce_account_order-a-kit_endpoint', 'my_custom_endpoint_content' );
?>
Any help is greatly appreciated.
As the "woocommerce" folder is inside your theme as the function.php file you just need to use:
include 'woocommerce/myaccount/order-a-kit.php';
See this related answer: WooCommerce: Adding custom template to customer account pages
Try this
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'woocommerce/myaccount/order-a-kit.php';
You can add this code to your theme's function.php:
class My_Custom_My_Account_Endpoint {
/**
* Custom endpoint name.
*
* #var string
*/
public static $endpoint = 'Your Desired Link';
/**
* Plugin actions.
*/
public function __construct() {
// Actions used to insert a new endpoint in the WordPress.
add_action( 'init', array( $this, 'add_endpoints' ) );
add_filter( 'query_vars', array( $this, 'add_query_vars' ), 0 );
// Change the My Accout page title.
add_filter( 'the_title', array( $this, 'endpoint_title' ) );
// Insering your new tab/page into the My Account page.
add_filter( 'woocommerce_account_menu_items', array( $this, 'new_menu_items' ) );
add_action( 'woocommerce_account_' . self::$endpoint . '_endpoint', array( $this, 'endpoint_content' ) );
}
/**
* Register new endpoint to use inside My Account page.
*
* #see https://developer.wordpress.org/reference/functions/add_rewrite_endpoint/
*/
public function add_endpoints() {
add_rewrite_endpoint( self::$endpoint, EP_ROOT | EP_PAGES );
}
/**
* Add new query var.
*
* #param array $vars
* #return array
*/
public function add_query_vars( $vars ) {
$vars[] = self::$endpoint;
return $vars;
}
/**
* Set endpoint title.
*
* #param string $title
* #return string
*/
public function endpoint_title( $title ) {
global $wp_query;
$is_endpoint = isset( $wp_query->query_vars[ self::$endpoint ] );
if ( $is_endpoint && ! is_admin() && is_main_query() && in_the_loop() && is_account_page() ) {
// New page title.
$title = __( 'Your Item Name', 'woocommerce' );
remove_filter( 'the_title', array( $this, 'endpoint_title' ) );
}
return $title;
}
/**
* Insert the new endpoint into the My Account menu.
*
* #param array $items
* #return array
*/
public function new_menu_items( $items ) {
// Remove the logout menu item.
$logout = $items['customer-logout'];
unset( $items['customer-logout'] );
// Insert your custom endpoint.
$items[ self::$endpoint ] = __( 'Your Item Name', 'woocommerce' );
// Insert back the logout item.
$items['customer-logout'] = $logout;
return $items;
}
/**
* Endpoint HTML content.
*/
public function endpoint_content() {
//example include('woocommerce/myaccount/Your-File.php');
include('Path-To-Your-File.php');
}
/**
* Plugin install action.
* Flush rewrite rules to make our custom endpoint available.
*/
public static function install() {
flush_rewrite_rules();
}
}
new My_Custom_My_Account_Endpoint();
// Flush rewrite rules on plugin activation.
register_activation_hook( __FILE__, array( 'My_Custom_My_Account_Endpoint', 'install' ) );
You have to simply set "Your Desired Link"x1 and "Your Item Name"x2 and "Path-To-Your-File.php"x1 in this source.
If you don't know where is your theme's function.php:
1.Log in to the WordPress Admin interface
2.In the left sidebar, hover over Appearances, then click Theme Editor
3.In the right sidebar, click functions.php

How do I flip images on the homepage using "Woocommerce Product Image Flipper" plugin?

I am using the Wordpress plugin "Woocommerce Product Image Flipper" to flip images on hover.
It works perfectly on a product category page, but the not on the homepage.
How do I make the images flip on the homepage?
I am displaying the Homepage Template and it shows the following sections:
"New In" , "On Sale", "Bestsellers"
When I hover over them, I would like the images to flip like they do on the product category pages.
The code of the plugin is as follows:
<?php
/*
Plugin Name: WooCommerce Product Image Flipper
Plugin URI:
Version: 0.4.0
Description: Adds a secondary image on product archives that is revealed on hover. Perfect for displaying front/back shots of clothing and other products.
Author: jameskoster
Author URI:
Text Domain: woocommerce-product-image-flipper
Domain Path: /languages/
License: GNU General Public License v3.0
License URI:
*/
/**
* Check if WooCommerce is active
*/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
/**
* Localisation (with WPML support)
*/
add_action( 'init', 'plugin_init' );
function plugin_init() {
load_plugin_textdomain( 'woocommerce-product-image-flipper', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
/**
* Image Flipper class
*/
if ( ! class_exists( 'WC_pif' ) ) {
class WC_pif {
public function __construct() {
add_action( 'wp_enqueue_scripts', array( $this, 'pif_scripts' ) );
add_action( 'woocommerce_before_shop_loop_item_title', array( $this, 'woocommerce_template_loop_second_product_thumbnail' ), 11 );
add_filter( 'post_class', array( $this, 'product_has_gallery' ) );
}
/**
* Class functions
*/
public function pif_scripts() {
if ( apply_filters( 'woocommerce_product_image_flipper_styles', true ) ) {
wp_enqueue_style( 'pif-styles', plugins_url( '/assets/css/style.css', __FILE__ ) );
}
}
public function product_has_gallery( $classes ) {
global $product;
$post_type = get_post_type( get_the_ID() );
if ( ! is_admin() ) {
if ( $post_type == 'product' ) {
$attachment_ids = $this->get_gallery_image_ids( $product );
if ( $attachment_ids ) {
$classes[] = 'pif-has-gallery';
}
}
}
return $classes;
}
/**
* Frontend functions
*/
public function woocommerce_template_loop_second_product_thumbnail() {
global $product, $woocommerce;
$attachment_ids = $this->get_gallery_image_ids( $product );
if ( $attachment_ids ) {
$attachment_ids = array_values( $attachment_ids );
$secondary_image_id = $attachment_ids['1'];
$secondary_image_alt = get_post_meta( $secondary_image_id, '_wp_attachment_image_alt', true );
$secondary_image_title = get_the_title($secondary_image_id);
echo wp_get_attachment_image(
$secondary_image_id,
'shop_catalog',
'',
array(
'class' => 'secondary-image attachment-shop-catalog wp-post-image wp-post-image--secondary',
'alt' => $secondary_image_alt,
'title' => $secondary_image_title
)
);
}
}
/**
* WooCommerce Compatibility Functions
*/
public function get_gallery_image_ids( $product ) {
if ( ! is_a( $product, 'WC_Product' ) ) {
return;
}
if ( is_callable( 'WC_Product::get_gallery_image_ids' ) ) {
return $product->get_gallery_image_ids();
} else {
return $product->get_gallery_attachment_ids();
}
}
}
$WC_pif = new WC_pif();
}
}

Wordpress: (When Fixing Overlapping Masonry Issue) Encountered unexpected end of file in functions.php

Disclosure: I'm not a programmer, or trained in web design. Please forgive me if this is something stupid.
Today I've been trying to fix a problem with overlapping Masonry on my Wordpress.org website: nathanhewitt.net. I found that the likely solution was to use imagesLoaded, a jquery script (imagesloaded.desandro.com). since this isn't my area of expertise, I didn't know how to use a jquery script so I went through many different forums, primarily using this and this as my guides on how to add them to the theme's functions.php file.
This is what I added, toward the top of the code (I'll put the full code below):
function my_scripts_method() {
// register your script location, dependencies and version
wp_register_script('imagesLoaded',
get_template_directory_uri() . '/custom_jquery/imagesloaded.pkgd.min.js',
array('jquery'),
'1.0' );
// enqueue the script
wp_enqueue_script('imagesLoaded');
}
add_action('wp_enqueue_scripts', 'my_scripts_method');
As soon as I added it, I began to get a Parse error: syntax error, unexpected end of file in /home/nathanhe/public_html/wp-content/themes/balance2/functions.php on line 359, but no matter how I shift the code around, copying and pasting and changing the order, it always says line 359.
I should mention that the code I added related to imagesLoaded is no where near line 359, and also that I have put the text through an online php checker and it didn't find any errors.
Does anyone have any idea what I've done wrong?
I've checked around for several hours and can't seem to figure this out; hopefully someone out there might also be having the same problem and might run into this forum.
Here's the full code:
<?php
require_once ( get_stylesheet_directory() . '/theme-options.php' );
if (!is_admin()) {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', get_bloginfo('stylesheet_directory').'/libs/jquery-1.6.1.min.js' );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery_masonry', get_bloginfo('stylesheet_directory').'/libs/jquery.masonry.min.js' );
wp_enqueue_script( 'jquery_ui', get_bloginfo('stylesheet_directory').'/libs/jquery-ui.custom.min.js' );
// javascript for infinite scroll
$imbalance2_theme_options = get_option('imbalance2_theme_options');
if ( $imbalance2_theme_options['navigation'] == 1 )
{
wp_enqueue_script( 'jquery_infinitescroll', get_bloginfo('stylesheet_directory').'/libs/jquery.infinitescroll.min.js' );
}
}
function my_scripts_method() {
// register your script location, dependencies and version
wp_register_script('imagesLoaded',
get_template_directory_uri() . '/custom_jquery/imagesloaded.pkgd.min.js',
array('jquery'),
'1.0' );
// enqueue the script
wp_enqueue_script('imagesLoaded');
}
add_action('wp_enqueue_scripts', 'my_scripts_method');
// shortcodes
function imbalance2_wide( $atts, $content = null )
{
return '<div class="wide">' . do_shortcode($content) . '</div>';
}
add_shortcode( 'wide', 'imbalance2_wide' );
function imbalance2_aside( $atts, $content = null )
{
return '<div class="aside">' . do_shortcode($content) . '</div>';
}
add_shortcode( 'aside', 'imbalance2_aside' );
// 210px width images for the grid
if ( function_exists( 'add_theme_support' ) )
{
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 210 );
}
if ( function_exists( 'add_image_size' ) )
{
add_image_size( 'homepage-thumb', 210 );
}
// font output for css
function getFonts()
{
global $imbalance2_theme_options;
if ($imbalance2_theme_options['font'] == 0) return 'Georgia, "Times New Roman", Serif';
return '"Helvetica Neue", Helvetica, Arial, "Sans-Serif"';
}
// favicon for <head>
function getFavicon()
{
global $imbalance2_theme_options;
return '<link rel="shortcut icon" href="'.($imbalance2_theme_options['favicon'] != '' ? $imbalance2_theme_options['favicon'] : get_bloginfo('stylesheet_directory').'/favico.ico').'" />';
}
// color option for css
function getColor()
{
global $imbalance2_theme_options;
return $imbalance2_theme_options['color'] != '' ? $imbalance2_theme_options['color'] : '#f05133';
}
// fluid grid option for css
function fluidGrid()
{
global $imbalance2_theme_options;
return $imbalance2_theme_options['fluid'];
}
// images only option for css
function imagesOnly()
{
global $imbalance2_theme_options;
return $imbalance2_theme_options['images_only'];
}
// google analytics
function imbalance2google()
{
global $imbalance2_theme_options;
return $imbalance2_theme_options['google'];
}
// custom menu
class Imbalance2_Walker_Nav_Menu extends Walker_Nav_Menu {
function start_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<div class=\"imbalance2_submenu_container\"><ul class=\"sub-menu\"><li><ul class=\"imbalance2_submenu\">\n";
}
function end_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "$indent</ul></li></ul></div>\n";
}
}
/**
* Functions and definitions
*/
/**
* Set the content width based on the theme's design and stylesheet.
*
* Used to set the width of images and content. Should be equal to the width the theme
* is designed for, generally via the style.css stylesheet.
*/
if ( ! isset( $content_width ) )
$content_width = 720;
/** Tell WordPress to run imbalance2_setup() when the 'after_setup_theme' hook is run. */
add_action( 'after_setup_theme', 'imbalance2_setup' );
if ( ! function_exists( 'imbalance2_setup' ) ):
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which runs
* before the init hook. The init hook is too late for some features, such as indicating
* support post thumbnails.
*
* To override imbalance2_setup() in a child theme, add your own imbalance2_setup to your child theme's
* functions.php file.
*
* #uses add_theme_support() To add support for post thumbnails and automatic feed links.
* #uses register_nav_menus() To add support for navigation menus.
* #uses add_custom_background() To add support for a custom background.
* #uses add_editor_style() To style the visual editor.
* #uses load_theme_textdomain() For translation/localization support.
* #uses add_custom_image_header() To add support for a custom header.
* #uses register_default_headers() To register the default custom header images provided with the theme.
* #uses set_post_thumbnail_size() To set a custom post thumbnail size.
*
* #since Twenty Ten 1.0
*/
function imbalance2_setup() {
// This theme styles the visual editor with editor-style.css to match the theme style.
add_editor_style();
// This theme uses post thumbnails
add_theme_support( 'post-thumbnails' );
// Add default posts and comments RSS feed links to head
add_theme_support( 'automatic-feed-links' );
// Make theme available for translation
// Translations can be filed in the /languages/ directory
load_theme_textdomain( 'imbalance2', TEMPLATEPATH . '/languages' );
$locale = get_locale();
$locale_file = TEMPLATEPATH . "/languages/$locale.php";
if ( is_readable( $locale_file ) )
require_once( $locale_file );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'header-left' => __( 'Header Left Navigation', 'imbalance2' ),
'header-center' => __( 'Header Center Navigation', 'imbalance2' ),
'header-right' => __( 'Header Right Navigation', 'imbalance2' ),
'footer-left' => __( 'Footer Left Navigation', 'imbalance2' ),
'footer-right' => __( 'Footer Right Navigation', 'imbalance2' )
) );
}
endif;
/**
* Sets the post excerpt length to 40 characters.
*
* To override this length in a child theme, remove the filter and add your own
* function tied to the excerpt_length filter hook.
*
* #since Twenty Ten 1.0
* #return int
*/
function imbalance2_excerpt_length( $length ) {
return 40;
}
add_filter( 'excerpt_length', 'imbalance2_excerpt_length' );
/**
* Replaces "[...]" (appended to automatically generated excerpts).
*
* To override this in a child theme, remove the filter and add your own
* function tied to the excerpt_more filter hook.
*
* #since Twenty Ten 1.0
* #return string An ellipsis
*/
function imbalance2_auto_excerpt_more( $more ) {
return '';
}
add_filter( 'excerpt_more', 'imbalance2_auto_excerpt_more' );
/**
* Remove inline styles printed when the gallery shortcode is used.
*
* Galleries are styled by the theme in Twenty Ten's style.css. This is just
* a simple filter call that tells WordPress to not use the default styles.
*
* #since Twenty Ten 1.2
*/
add_filter( 'use_default_gallery_style', '__return_false' );
/**
* Deprecated way to remove inline styles printed when the gallery shortcode is used.
*
* This function is no longer needed or used. Use the use_default_gallery_style
* filter instead, as seen above.
*
* #since Twenty Ten 1.0
* #deprecated Deprecated in Twenty Ten 1.2 for WordPress 3.1
*
* #return string The gallery style filter, with the styles themselves removed.
*/
function imbalance2_remove_gallery_css( $css ) {
return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
}
// Backwards compatibility with WordPress 3.0.
if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) )
add_filter( 'gallery_style', 'imbalance2_remove_gallery_css' );
if ( ! function_exists( 'imbalance2_comment' ) ) :
/**
* Template for comments and pingbacks.
*
* To override this walker in a child theme without modifying the comments template
* simply create your own imbalance2_comment(), and that function will be used instead.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*
* #since Twenty Ten 1.0
*/
function imbalance2_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case '' :
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-avatar">
<?php echo get_avatar( $comment, 60 ); ?>
</div>
<?php if ( $comment->comment_approved == '0' ) : ?>
<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'imbalance2' ); ?></em>
<br />
<?php endif; ?>
<div class="comment-author">
<?php printf( __( '%s', 'imbalance2' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
</div>
<div class="comment-meta commentmetadata">
<?php
/* translators: 1: date, 2: time */
printf( __( '%1$s at %2$s', 'imbalance2' ), get_comment_date(), get_comment_time() ); ?><?php edit_comment_link( __( '(Edit)', 'imbalance2' ), ' ' );
?>
</div><!-- .comment-meta .commentmetadata -->
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div><!-- .reply -->
<div class="comment-body"><?php comment_text(); ?></div>
</div><!-- #comment-## -->
<?php
break;
case 'pingback' :
case 'trackback' :
?>
<li class="post pingback">
<p><?php _e( 'Pingback:', 'imbalance2' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'imbalance2' ), ' ' ); ?></p>
<?php
break;
endswitch;
}
endif;
/**
* Removes the default styles that are packaged with the Recent Comments widget.
*
* To override this in a child theme, remove the filter and optionally add your own
* function tied to the widgets_init action hook.
*
* This function uses a filter (show_recent_comments_widget_style) new in WordPress 3.1
* to remove the default style. Using Twenty Ten 1.2 in WordPress 3.0 will show the styles,
* but they won't have any effect on the widget in default Twenty Ten styling.
*
* #since Twenty Ten 1.0
*/
function imbalance2_remove_recent_comments_style() {
add_filter( 'show_recent_comments_widget_style', '__return_false' );
}
add_action( 'widgets_init', 'imbalance2_remove_recent_comments_style' );
if ( ! function_exists( 'imbalance2_posted_by' ) ) :
function imbalance2_posted_by() {
printf( __( '<span class="meta-sep">By</span> %1$s', 'imbalance2' ),
sprintf( '%3$s',
get_author_posts_url( get_the_author_meta( 'ID' ) ),
sprintf( esc_attr__( 'View all posts by %s', 'imbalance2' ), get_the_author() ),
get_the_author()
)
);
}
endif;
if ( ! function_exists( 'imbalance2_posted_on' ) ) :
function imbalance2_posted_on() {
printf( __( '%1$s', 'imbalance2' ),
sprintf( '<span class="entry-date">%1$s</span>',
get_the_date()
)
);
}
endif;
if ( ! function_exists( 'imbalance2_posted_in' ) ) :
function imbalance2_posted_in() {
if ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
$posted_in = __( '%1$s', 'imbalance2' );
} else {
$posted_in = __( 'Bookmark the permalink.', 'imbalance2' );
}
printf(
$posted_in,
get_the_category_list( ', ' ),
get_permalink(),
the_title_attribute( 'echo=0' )
);
}
endif;
if ( ! function_exists( 'imbalance2_tags' ) ) :
function imbalance2_tags() {
$tag_list = get_the_tag_list( '', ', ' );
if ( $tag_list ) printf(__( '<div class="entry-tags"><span>Tags:</span> %1$s</div>', 'imbalance2' ), $tag_list );
}
endif;
function wpse_custom_header_setup() {
add_theme_support( 'custom-header', apply_filters( 'wpse_header_args', array(
'width' => 1460,
'height' => 220,
) ) );
}
add_action( 'after_setup_theme', 'wpse_custom_header_setup' );
?>
It is the problem of character encoding while saving your file after editing. It may be due to the file editor or Charset setting in FTP you are using to upload. You need to select UTF-8 character set.
To overcome this issue, follow below instructions:
Create a new file in notepad++ and Copy all the content of the editing file(functions.php) and paste it in this new file.
Click on 'Encoding' menu and select 'Encode in UTF-8' to apply UTF-8 character encoding.
Now, save this file as named 'functions.php' and upload it.
If it doesn't work, you can select 'Force in UTF-8' under 'charset' tab in FTP manger(like FileZilla) you are using.

Wordpress editor-style.css not working

I want to add an editor-style.css file so I can change the editor styles to match my template.
I've added the following to the top of my functions.php file:
function my_theme_add_editor_styles() {
add_editor_style( 'editor-style.css' );
}
add_action( 'init', 'my_theme_add_editor_styles' );
This isn't working though, am I putting it in the right place?
/* ========================================================================================================================
Required external files
======================================================================================================================== */
require_once( 'external/starkers-utilities.php' );
/* ========================================================================================================================
Theme specific settings
Uncomment register_nav_menus to enable a single menu with the title of "Primary Navigation" in your theme
======================================================================================================================== */
add_theme_support('post-thumbnails');
// register_nav_menus(array('primary' => 'Primary Navigation'));
/* ========================================================================================================================
Actions and Filters
======================================================================================================================== */
add_action( 'wp_enqueue_scripts', 'starkers_script_enqueuer' );
add_filter( 'body_class', array( 'Starkers_Utilities', 'add_slug_to_body_class' ) );
/* ========================================================================================================================
Custom Post Types - include custom post types and taxonimies here e.g.
e.g. require_once( 'custom-post-types/your-custom-post-type.php' );
======================================================================================================================== */
add_editor_style( $stylesheet ); /* ========================================================================================================================
Scripts
======================================================================================================================== */
/**
* Add scripts via wp_head()
*
* #return void
* #author Keir Whitaker
*/
function starkers_script_enqueuer() {
wp_register_script( 'site', get_template_directory_uri().'/js/site.js', array( 'jquery' ) );
wp_enqueue_script( 'site' );
wp_register_style( 'screen', get_stylesheet_directory_uri().'/style.css', '', '', 'screen' );
wp_enqueue_style( 'screen' );
}
/* ========================================================================================================================
Comments
======================================================================================================================== */
/**
* Custom callback for outputting comments
*
* #return void
* #author Keir Whitaker
*/
function starkers_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
?>
<?php if ( $comment->comment_approved == '1' ): ?>
<li>
<article id="comment-<?php comment_ID() ?>">
<?php echo get_avatar( $comment ); ?>
<h4><?php comment_author_link() ?></h4>
<time><a href="#comment-<?php comment_ID() ?>" pubdate><?php comment_date() ?> at <?php comment_time() ?></a></time>
<?php comment_text() ?>
</article>
<?php endif;
}
Try this:
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, icons, and column width.
*/
add_editor_style( array( 'css/editor-style.css', twentysixteen_fonts_url() ) );
// Load regular editor styles into the new block-based editor.
add_theme_support( 'editor-styles' );
// Load default block styles.
add_theme_support( 'wp-block-styles' );

Categories