functions.php #865
Replies: 7 comments 7 replies
-
Hello, we would like to help here, the problem is that your code is too much and unreadable. Please use GitHub markdown to create highlighting code blocks and make sure that they are well formatted. In your case, showing PHP:
At least, please do not show the entire file, only the snippet that you want to add/change. BTW, having a quick look to your code tells me that you are editing a very outdated v5 parent-theme directly. You should always use a child to edit your project and keep parent-theme as it is and up-to-date. If this is a new project, I highly recommend to switch latest v6 parent- and child-theme. Both are available on https://bootscore.me/#download 4free. |
Beta Was this translation helpful? Give feedback.
-
hello yes the new version is good sorry for my mistakes functions.php how do i add new js and css thanks for your help This is what I want to do Presento When I add the files in this main.css, the theme breaks. How should I do it? thanks |
Beta Was this translation helpful? Give feedback.
-
hello thank you for your help i have been dealing with this for 3 days but i couldn't solve it i am waiting for your help |
Beta Was this translation helpful? Give feedback.
-
functions.zip |
Beta Was this translation helpful? Give feedback.
-
pardon,come here first time ,and cant say anything |
Beta Was this translation helpful? Give feedback.
-
你好,来信已经收到,尽快给你回复。 Rosing
|
Beta Was this translation helpful? Give feedback.
-
test.zip |
Beta Was this translation helpful? Give feedback.
-
hello
i have been using it for a long time, i am satisfied, thank you
i tried it on a new project today
i am having trouble embedding css and js files that i call from outside to functions.php
original version
`<?php
/**
*/
// WooCommerce
//require get_template_directory() . '/woocommerce/woocommerce-functions.php';
// WooCommerce END
// Register Bootstrap 5 Nav Walker
if (!function_exists('register_navwalker')) :
function register_navwalker() {
require_once('inc/class-bootstrap-5-navwalker.php');
// Register Menus
register_nav_menu('main-menu', 'Main menu');
register_nav_menu('footer-menu', 'Footer menu');
}
endif;
add_action('after_setup_theme', 'register_navwalker');
// Register Bootstrap 5 Nav Walker END
// Register Comment List
if (!function_exists('register_comment_list')) :
function register_comment_list() {
// Register Comment List
require_once('inc/comment-list.php');
}
endif;
add_action('after_setup_theme', 'register_comment_list');
// Register Comment List END
if (!function_exists('bootscore_setup')) :
/**
/
function bootscore_setup() {
/
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Bootscore, use a find and replace
* to change 'bootscore' to the name of your theme in all the template files.
*/
load_theme_textdomain('bootscore', get_template_directory() . '/languages');
}
endif;
add_action('after_setup_theme', 'bootscore_setup');
/**
*/
function bootscore_content_width() {
// This variable is intended to be overruled from themes.
// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$GLOBALS['content_width'] = apply_filters('bootscore_content_width', 640);
}
add_action('after_setup_theme', 'bootscore_content_width', 0);
/**
*/
// Widgets
if (!function_exists('bootscore_widgets_init')) :
function bootscore_widgets_init() {
}
add_action('widgets_init', 'bootscore_widgets_init');
endif;
// Widgets END
// Shortcode in HTML-Widget
add_filter('widget_text', 'do_shortcode');
// Shortcode in HTML-Widget End
//Enqueue scripts and styles
function bootscore_scripts() {
// Get modification time. Enqueue files with modification date to prevent browser from loading cached scripts and styles when file content changes.
$modificated_styleCss = date('YmdHi', filemtime(get_stylesheet_directory() . '/style.css'));
if (file_exists(get_template_directory() . '/css/main.css')) {
$modificated_bootscoreCss = date('YmdHi', filemtime(get_template_directory() . '/css/main.css'));
} else {
$modificated_bootscoreCss = 1;
}
$modificated_fontawesomeCss = date('YmdHi', filemtime(get_template_directory() . '/css/lib/fontawesome.min.css'));
$modificated_bootstrapJs = date('YmdHi', filemtime(get_template_directory() . '/js/lib/bootstrap.bundle.min.js'));
$modificated_themeJs = date('YmdHi', filemtime(get_template_directory() . '/js/theme.js'));
// Style CSS
wp_enqueue_style('bootscore-style', get_stylesheet_uri(), array(), $modificated_styleCss);
// bootScore
require_once 'inc/scss-compiler.php';
bootscore_compile_scss();
wp_enqueue_style('main', get_template_directory_uri() . '/css/main.css', array(), $modificated_bootscoreCss);
// Fontawesome
wp_enqueue_style('fontawesome', get_template_directory_uri() . '/css/lib/fontawesome.min.css', array(), $modificated_fontawesomeCss);
// Bootstrap JS
wp_enqueue_script('bootstrap', get_template_directory_uri() . '/js/lib/bootstrap.bundle.min.js', array(), $modificated_bootstrapJs, true);
// Theme JS
wp_enqueue_script('bootscore-script', get_template_directory_uri() . '/js/theme.js', array('jquery'), $modificated_themeJs, true);
// IE Warning
wp_localize_script('bootscore-script', 'bootscore', array(
'ie_title' => __('Internet Explorer detected', 'bootscore'),
'ie_limited_functionality' => __('This website will offer limited functionality in this browser.', 'bootscore'),
'ie_modern_browsers_1' => __('Please use a modern and secure web browser like', 'bootscore'),
'ie_modern_browsers_2' => __(' Mozilla Firefox, Google Chrome, Opera ' , 'bootscore'),
'ie_modern_browsers_3' => __('or', 'bootscore'),
'ie_modern_browsers_4' => __(' Microsoft Edge ' , 'bootscore'),
'ie_modern_browsers_5' => __('to display this site correctly.', 'bootscore'),
));
// IE Warning End
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
}
add_action('wp_enqueue_scripts', 'bootscore_scripts');
//Enqueue scripts and styles END
// Add to Fontawesome
add_filter('style_loader_tag', 'wpse_231597_style_loader_tag');
function wpse_231597_style_loader_tag($tag) {
$tag = preg_replace("/id='font-awesome-css'/", "id='font-awesome-css' online="if(media!='all')media='all'"", $tag);
return $tag;
}
// Add to Fontawesome END
/**
*/
require get_template_directory() . '/inc/template-tags.php';
/**
*/
require get_template_directory() . '/inc/template-functions.php';
/**
*/
if (defined('JETPACK__VERSION')) {
require get_template_directory() . '/inc/jetpack.php';
}
// Amount of posts/products in category
if (!function_exists('wpsites_query')) :
function wpsites_query($query) {
if ($query->is_archive() && $query->is_main_query() && !is_admin()) {
$query->set('posts_per_page', 24);
}
}
add_action('pre_get_posts', 'wpsites_query');
endif;
// Amount of posts/products in category END
// Pagination Categories
if (!function_exists('bootscore_pagination')) :
function bootscore_pagination($pages = '', $range = 2) {
$showitems = ($range * 2) + 1;
global $paged;
if ($pages == '') {
global $wp_query;
$pages = $wp_query->max_num_pages;
}
endif;
//Pagination Categories END
// Pagination Buttons Single Posts
add_filter('next_post_link', 'post_link_attributes');
add_filter('previous_post_link', 'post_link_attributes');
function post_link_attributes($output) {
$code = 'class="page-link"';
return str_replace('<a href=', '<a ' . $code . ' href=', $output);
}
// Pagination Buttons Single Posts END
// Excerpt to pages
add_post_type_support('page', 'excerpt');
// Excerpt to pages END
// Breadcrumb
';if (!function_exists('the_breadcrumb')) :
function the_breadcrumb() {
if (!is_home()) {
echo '
echo '' . ('') . ' / ';
if (is_category() || is_single()) {
the_category(' / ');
if (is_single()) {
echo ' / ';
the_title();
}
} elseif (is_page()) {
echo the_title();
}
echo '';
}
}
add_filter('breadcrumbs', 'breadcrumbs');
endif;
// Breadcrumb END
// Comment Button
function bootscore_comment_form($args) {
$args['class_submit'] = 'btn btn-outline-primary'; // since WP 4.1
return $args;
}
add_filter('comment_form_defaults', 'bootscore_comment_form');
// Comment Button END
// Password protected form
' . "\n"function bootscore_pw_form() {
$output = '
. '' . "\n"
. '' . "\n"
. '' . "\n"
. '' . "\n";
return $output;
}
add_filter("the_password_form", "bootscore_pw_form");
// Password protected form END
// Allow HTML in term (category, tag) descriptions
foreach (array('pre_term_description') as $filter) {
remove_filter($filter, 'wp_filter_kses');
if (!current_user_can('unfiltered_html')) {
add_filter($filter, 'wp_filter_post_kses');
}
}
foreach (array('term_description') as $filter) {
remove_filter($filter, 'wp_kses_data');
}
// Allow HTML in term (category, tag) descriptions END
// Allow HTML in author bio
remove_filter('pre_user_description', 'wp_filter_kses');
add_filter('pre_user_description', 'wp_filter_post_kses');
// Allow HTML in author bio END
// Hook after #primary
function bs_after_primary() {
do_action('bs_after_primary');
}
// Hook after #primary END
// Open links in comments in new tab
if (!function_exists('bs_comment_links_in_new_tab')) :
function bs_comment_links_in_new_tab($text) {
return str_replace('<a', '<a target="_blank" rel=”nofollow”', $text);
}
add_filter('comment_text', 'bs_comment_links_in_new_tab');
endif;
// Open links in comments in new tab END
// Disable Gutenberg blocks in widgets (WordPress 5.8)
// Disables the block editor from managing widgets in the Gutenberg plugin.
add_filter('gutenberg_use_widgets_block_editor', '__return_false');
// Disables the block editor from managing widgets.
add_filter('use_widgets_block_editor', '__return_false');
// Disable Gutenberg blocks in widgets (WordPress 5.8) END
`
What I want to add
`<?php
/**
*/
// WooCommerce
//require get_template_directory() . '/woocommerce/woocommerce-functions.php';
// WooCommerce END
// Register Bootstrap 5 Nav Walker
if (!function_exists('register_navwalker')) :
function register_navwalker() {
require_once('inc/class-bootstrap-5-navwalker.php');
// Register Menus
register_nav_menu('main-menu', 'Main menu');
register_nav_menu('footer-menu', 'Footer menu');
}
endif;
add_action('after_setup_theme', 'register_navwalker');
// Register Bootstrap 5 Nav Walker END
// Register Comment List
if (!function_exists('register_comment_list')) :
function register_comment_list() {
// Register Comment List
require_once('inc/comment-list.php');
}
endif;
add_action('after_setup_theme', 'register_comment_list');
// Register Comment List END
if (!function_exists('bootscore_setup')) :
/**
/
function bootscore_setup() {
/
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Bootscore, use a find and replace
* to change 'bootscore' to the name of your theme in all the template files.
*/
load_theme_textdomain('bootscore', get_template_directory() . '/languages');
}
endif;
add_action('after_setup_theme', 'bootscore_setup');
/**
*/
function bootscore_content_width() {
// This variable is intended to be overruled from themes.
// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$GLOBALS['content_width'] = apply_filters('bootscore_content_width', 640);
}
add_action('after_setup_theme', 'bootscore_content_width', 0);
/**
*/
// Widgets
if (!function_exists('bootscore_widgets_init')) :
function bootscore_widgets_init() {
}
add_action('widgets_init', 'bootscore_widgets_init');
endif;
// Widgets END
// Shortcode in HTML-Widget
add_filter('widget_text', 'do_shortcode');
// Shortcode in HTML-Widget End
//Enqueue scripts and styles
function bootscore_scripts() {
// Get modification time. Enqueue files with modification date to prevent browser from loading cached scripts and styles when file content changes.
$modificated_styleCss = date('YmdHi', filemtime(get_stylesheet_directory() . '/style.css'));
if (file_exists(get_template_directory() . '/servis/assets/js/main.css')) {
$modificated_bootscoreCss = date('YmdHi', filemtime(get_template_directory() . '/servis/assets/js/main.css'));
} else {
$modificated_bootscoreCss = 1;
}
$modificated_fontawesomeCss = date('YmdHi', filemtime(get_template_directory() . '/css/lib/fontawesome.min.css'));
$modificated_bootstrapJs = date('YmdHi', filemtime(get_template_directory() . '/js/lib/bootstrap.bundle.min.js'));
$modificated_themeJs = date('YmdHi', filemtime(get_template_directory() . '/js/theme.js'));
// Style CSS
wp_enqueue_style('bootscore-style', get_stylesheet_uri(), array(), $modificated_styleCss);
// bootScore
require_once 'inc/scss-compiler.php';
bootscore_compile_scss();
wp_enqueue_style('main', get_template_directory_uri() . '/servis/assets/js/main.css', array(), $modificated_bootscoreCss);
// Fontawesome
wp_enqueue_style('fontawesome', get_template_directory_uri() . '/css/lib/fontawesome.min.css', array(), $modificated_fontawesomeCss);
// bootstrap-min-Css
wp_enqueue_style('bootstrap-min', get_template_directory_uri() . '/servis/assets/vendor/bootstrap/css/bootstrap.min.css', array(), $modificated_bootstrapminCss);
// bootstrap-icons-Css
wp_enqueue_style('bootstrap-icons', get_template_directory_uri() . '/servis/assets/vendor/bootstrap-icons/bootstrap-icons.css', array(), $modificated_bootstrapiconsCss);
// aos-Css
wp_enqueue_style('aos', get_template_directory_uri() . '/servis/assets/vendor/aos/aos.css', array(), $modificated_aosCss);
// glightbox-min-Css
wp_enqueue_style('glightbox-min', get_template_directory_uri() . '/servis/assets/vendor/glightbox/css/glightbox.min.css', array(), $modificated_glightboxminCss);
// swiper-bundle.min-Css
wp_enqueue_style('swiper-bundle.min', get_template_directory_uri() . '/servis/assets/vendor/swiper/swiper-bundle.min.css', array(), $modificated_swiperbundleminCss);
// Bootstrap JS
wp_enqueue_script('bootstrap', get_template_directory_uri() . '/js/lib/bootstrap.bundle.min.js', array(), $modificated_bootstrapJs, true);
// Theme JS
wp_enqueue_script('bootscore-script', get_template_directory_uri() . '/js/theme.js', array('jquery'), $modificated_themeJs, true);
// bootstrap-bundle-min-Js
wp_enqueue_script('bootstrap-bundle-min-Js', get_template_directory_uri() . '/servis/assets/vendor/bootstrap/js/bootstrap.bundle.min.js', array('jquery'), $modificated_bootstrapbundleminJs, true);
// validate-Js
wp_enqueue_script('validate-js', get_template_directory_uri() . '/servis/assets/vendor/php-email-form/validate.js', array('jquery'), $modificated_validateJs, true);
// aos-Js
wp_enqueue_script('aos-js', get_template_directory_uri() . '/servis/assets/vendor/aos/aos.js', array('jquery'), $modificated_aosJs, true);
// glightbox-min-Js
wp_enqueue_script('glightbox-min-js', get_template_directory_uri() . '/servis/assets/vendor/glightbox/js/glightbox.min.js', array('jquery'), $modificated_glightboxminJs, true);
// swiper-bundle-min-Js
wp_enqueue_script('swiper-bundle-min-js', get_template_directory_uri() . '/servis/assets/vendor/swiper/swiper-bundle.min.js', array('jquery'), $modificated_swiperbundleminJs, true);
// purecounter-vanilla-Js
wp_enqueue_script('purecounter-vanilla-js', get_template_directory_uri() . '/servis/assets/vendor/purecounter/purecounter_vanilla.js', array('jquery'), $modificated_purecountervanillaJs, true);
// imagesloaded-pkgd-min-Js
wp_enqueue_script('imagesloaded-pkgd-min-Js', get_template_directory_uri() . '/servis/assets/vendor/imagesloaded/imagesloaded.pkgd.min.js', array('jquery'), $modificated_imagesloadedpkgdminJs, true);
// isotope.pkgd-min-Js
wp_enqueue_script('isotope.pkgd-min-Js', get_template_directory_uri() . '/servis/assets/vendor/isotope-layout/isotope.pkgd.min.js', array('jquery'), $modificated_isotopepkgdminJs, true);
// main-Js
wp_enqueue_script('main-Js', get_template_directory_uri() . '/servis/assets/js/main.js', array('jquery'), $modificated_mainJs, true);
// IE Warning
wp_localize_script('bootscore-script', 'bootscore', array(
'ie_title' => __('Internet Explorer detected', 'bootscore'),
'ie_limited_functionality' => __('This website will offer limited functionality in this browser.', 'bootscore'),
'ie_modern_browsers_1' => __('Please use a modern and secure web browser like', 'bootscore'),
'ie_modern_browsers_2' => __(' Mozilla Firefox, Google Chrome, Opera ' , 'bootscore'),
'ie_modern_browsers_3' => __('or', 'bootscore'),
'ie_modern_browsers_4' => __(' Microsoft Edge ' , 'bootscore'),
'ie_modern_browsers_5' => __('to display this site correctly.', 'bootscore'),
));
// IE Warning End
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
}
add_action('wp_enqueue_scripts', 'bootscore_scripts');
//Enqueue scripts and styles END
// Add to Fontawesome
add_filter('style_loader_tag', 'wpse_231597_style_loader_tag');
function wpse_231597_style_loader_tag($tag) {
$tag = preg_replace("/id='font-awesome-css'/", "id='font-awesome-css' online="if(media!='all')media='all'"", $tag);
return $tag;
}
// Add to Fontawesome END
/**
*/
require get_template_directory() . '/inc/template-tags.php';
/**
*/
require get_template_directory() . '/inc/template-functions.php';
/**
*/
if (defined('JETPACK__VERSION')) {
require get_template_directory() . '/inc/jetpack.php';
}
// Amount of posts/products in category
if (!function_exists('wpsites_query')) :
function wpsites_query($query) {
if ($query->is_archive() && $query->is_main_query() && !is_admin()) {
$query->set('posts_per_page', 24);
}
}
add_action('pre_get_posts', 'wpsites_query');
endif;
// Amount of posts/products in category END
// Pagination Categories
if (!function_exists('bootscore_pagination')) :
function bootscore_pagination($pages = '', $range = 2) {
$showitems = ($range * 2) + 1;
global $paged;
if ($pages == '') {
global $wp_query;
$pages = $wp_query->max_num_pages;
}
endif;
//Pagination Categories END
// Pagination Buttons Single Posts
add_filter('next_post_link', 'post_link_attributes');
add_filter('previous_post_link', 'post_link_attributes');
function post_link_attributes($output) {
$code = 'class="page-link"';
return str_replace('<a href=', '<a ' . $code . ' href=', $output);
}
// Pagination Buttons Single Posts END
// Excerpt to pages
add_post_type_support('page', 'excerpt');
// Excerpt to pages END
// Breadcrumb
';if (!function_exists('the_breadcrumb')) :
function the_breadcrumb() {
if (!is_home()) {
echo '
echo '' . ('') . ' / ';
if (is_category() || is_single()) {
the_category(' / ');
if (is_single()) {
echo ' / ';
the_title();
}
} elseif (is_page()) {
echo the_title();
}
echo '';
}
}
add_filter('breadcrumbs', 'breadcrumbs');
endif;
// Breadcrumb END
// Comment Button
function bootscore_comment_form($args) {
$args['class_submit'] = 'btn btn-outline-primary'; // since WP 4.1
return $args;
}
add_filter('comment_form_defaults', 'bootscore_comment_form');
// Comment Button END
// Password protected form
' . "\n"function bootscore_pw_form() {
$output = '
. '' . "\n"
. '' . "\n"
. '' . "\n"
. '' . "\n";
return $output;
}
add_filter("the_password_form", "bootscore_pw_form");
// Password protected form END
// Allow HTML in term (category, tag) descriptions
foreach (array('pre_term_description') as $filter) {
remove_filter($filter, 'wp_filter_kses');
if (!current_user_can('unfiltered_html')) {
add_filter($filter, 'wp_filter_post_kses');
}
}
foreach (array('term_description') as $filter) {
remove_filter($filter, 'wp_kses_data');
}
// Allow HTML in term (category, tag) descriptions END
// Allow HTML in author bio
remove_filter('pre_user_description', 'wp_filter_kses');
add_filter('pre_user_description', 'wp_filter_post_kses');
// Allow HTML in author bio END
// Hook after #primary
function bs_after_primary() {
do_action('bs_after_primary');
}
// Hook after #primary END
// Open links in comments in new tab
if (!function_exists('bs_comment_links_in_new_tab')) :
function bs_comment_links_in_new_tab($text) {
return str_replace('<a', '<a target="_blank" rel=”nofollow”', $text);
}
add_filter('comment_text', 'bs_comment_links_in_new_tab');
endif;
// Open links in comments in new tab END
// Disable Gutenberg blocks in widgets (WordPress 5.8)
// Disables the block editor from managing widgets in the Gutenberg plugin.
add_filter('gutenberg_use_widgets_block_editor', '__return_false');
// Disables the block editor from managing widgets.
add_filter('use_widgets_block_editor', '__return_false');
// Disable Gutenberg blocks in widgets (WordPress 5.8) END
`
These are the things I want to add
<script src="https://buzdolabiservissiemens.com.tr/wp-content/themes/bootscore-main/servis/assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script> <script src="https://buzdolabiservissiemens.com.tr/wp-content/themes/bootscore-main/servis/assets/vendor/php-email-form/validate.js"></script> <script src="https://buzdolabiservissiemens.com.tr/wp-content/themes/bootscore-main/servis/assets/vendor/aos/aos.js"></script> <script src="https://buzdolabiservissiemens.com.tr/wp-content/themes/bootscore-main/servis/assets/vendor/glightbox/js/glightbox.min.js"></script> <script src="https://buzdolabiservissiemens.com.tr/wp-content/themes/bootscore-main/servis/assets/vendor/swiper/swiper-bundle.min.js"></script> <script src="https://buzdolabiservissiemens.com.tr/wp-content/themes/bootscore-main/servis/assets/vendor/purecounter/purecounter_vanilla.js"></script> <script src="https://buzdolabiservissiemens.com.tr/wp-content/themes/bootscore-main/servis/assets/vendor/imagesloaded/imagesloaded.pkgd.min.js"></script> <script src="https://buzdolabiservissiemens.com.tr/wp-content/themes/bootscore-main/servis/assets/vendor/isotope-layout/isotope.pkgd.min.js"></script> <script src="https://buzdolabiservissiemens.com.tr/wp-content/themes/bootscore-main/servis/assets/js/main.js"></script>Thank you in advance for your help.
Beta Was this translation helpful? Give feedback.
All reactions