File: /home/httpd/vhosts/rajlaw.com.tw/httpdocs/wp-content/themes/advokat/inc/template-functions.php
<?php
/**
* @author rs-theme
* @since 1.0
* @version 1.0
*/
/**
* Adds custom classes to the array of body classes.
*
* @param array $classes Classes for the body element.
* @return array
*/
function advokat_body_classes( $classes ) {
// Adds a class of hfeed to non-singular pages.
if ( ! is_singular() ) {
$classes[] = 'hfeed';
}
return $classes;
}
add_filter( 'body_class', 'advokat_body_classes' );
/**
* Add a pingback url auto-discovery header for singularly identifiable articles.
*/
function advokat_pingback_header() {
if ( is_singular() && pings_open() ) {
echo '<link rel="pingback" href="', esc_url( get_bloginfo( 'pingback_url' ) ), '">';
}
}
add_action( 'wp_head', 'advokat_pingback_header' );
/*
Register Fonts theme google font
*/
function advokat_studio_fonts_url() {
$font_url = '';
/*
Translators: If there are characters in your language that are not supported
by chosen font(s), translate this to 'off'. Do not translate into your own language.
*/
if ( 'off' !== _x( 'on', 'Google font: on or off', 'advokat' ) ) {
$font_url = add_query_arg( 'family', urlencode( 'Open Sans: 300,400,500,600,700|Playfair Display:400,400i,700,700i,900' ), "//fonts.googleapis.com/css" );
}
return $font_url;
}
/*
Enqueue scripts and styles.
*/
function advokat_studio_scripts() {
wp_enqueue_style( 'studio-fonts', advokat_studio_fonts_url(), array(), '1.0.0' );
}
add_action( 'wp_enqueue_scripts', 'advokat_studio_scripts' );
//Favicon Icon
function advokat_site_icon() {
if ( ! ( function_exists( 'has_site_icon' ) && has_site_icon() ) ) {
global $advokat_option;
if(!empty($advokat_option['rs_favicon']['url']))
{?>
<link rel="shortcut icon" type="image/x-icon" href="<?php echo esc_url(($advokat_option['rs_favicon']['url'])); ?>">
<?php
}
}
}
add_filter('wp_head', 'advokat_site_icon');
//excerpt for specific section
function advokat_wpex_get_excerpt( $args = array() ) {
// Defaults
$defaults = array(
'post' => '',
'length' => 48,
'readmore' => false,
'readmore_text' => esc_html__( 'read more', 'advokat' ),
'readmore_after' => '',
'custom_excerpts' => true,
'disable_more' => false,
);
// Apply filters
$defaults = apply_filters( 'advokat_wpex_get_excerpt_defaults', $defaults );
// Parse args
$args = wp_parse_args( $args, $defaults );
// Apply filters to args
$args = apply_filters( 'advokat_wpex_get_excerpt_args', $defaults );
// Extract
extract( $args );
// Get global post data
if ( ! $post ) {
global $post;
}
// Get post ID
$post_id = $post->ID;
// Check for custom excerpt
if ( $custom_excerpts && has_excerpt( $post_id ) ) {
$output = $post->post_excerpt;
}
// No custom excerpt...so lets generate one
else {
// Readmore link
$readmore_link = '<a href="' . get_permalink( $post_id ) . '" class="readmore">' . $readmore_text . $readmore_after . '</a>';
// Check for more tag and return content if it exists
if ( ! $disable_more && strpos( $post->post_content, '<!--more-->' ) ) {
$output = apply_filters( 'the_content', get_the_content( $readmore_text . $readmore_after ) );
}
// No more tag defined so generate excerpt using wp_trim_words
else {
// Generate excerpt
$output = wp_trim_words( strip_shortcodes( $post->post_content ), $length );
// Add readmore to excerpt if enabled
if ( $readmore ) {
$output .= apply_filters( 'advokat_wpex_readmore_link', $readmore_link );
}
}
}
// Apply filters and echo
return apply_filters( 'advokat_wpex_get_excerpt', $output );
}
add_filter( 'get_the_archive_title', function ( $title ) {
if( is_category() ) {
$title = single_cat_title( '', false );
}
return $title;
});
//Demo content file include here
function advokat_import_files() {
return array(
array(
'import_file_name' => 'Elementor Page Builder',
'categories' => array( 'Elementor' ),
'import_file_url' => trailingslashit( get_template_directory_uri() ) . 'ocdi/elementor/advokat-content.xml',
'import_widget_file_url' => trailingslashit( get_template_directory_uri() ) . 'ocdi/elementor/advokat-widget.wie',
'import_redux' => array(
array(
'file_url' => trailingslashit( get_template_directory_uri() ) . 'ocdi/elementor/advokat-options.json',
'option_name' => 'advokat_option',
),
),
'import_preview_image_url' => 'https://rstheme.com/products/wordpress/landing/advokat/demo1.jpg',
'import_notice' => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page. For more info plesae read the documentation carefully.', 'advokat' ),
),
array(
'import_file_name' => 'WP Bakery Page Builder',
'categories' => array( 'WP Bakery' ),
'import_file_url' => trailingslashit( get_template_directory_uri() ) . 'ocdi/advokat-content.xml',
'import_widget_file_url' => trailingslashit( get_template_directory_uri() ) . 'ocdi/advokat-widget.wie',
'import_redux' => array(
array(
'file_url' => trailingslashit( get_template_directory_uri() ) . 'ocdi/advokat-options.json',
'option_name' => 'advokat_option',
),
),
'import_preview_image_url' => 'https://rstheme.com/products/wordpress/landing/advokat/demo1.jpg',
'import_notice' => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'advokat' ),
),
);
}
add_filter( 'pt-ocdi/import_files', 'advokat_import_files' );
function advokat_after_import_setup() {
// Assign menus to their locations.
$main_menu = get_term_by( 'name', 'Primary Menu', 'nav_menu' );
set_theme_mod( 'nav_menu_locations', array(
'menu-1' => $main_menu->term_id
)
);
// Assign front page and posts page (blog page).
$front_page_id = get_page_by_title( 'Home' );
$blog_page_id = get_page_by_title( 'Blog' );
update_option( 'show_on_front', 'page' );
update_option( 'page_on_front', $front_page_id->ID );
update_option( 'page_for_posts', $blog_page_id->ID );
//Import Revolution Slider
if ( class_exists( 'RevSlider' ) ) {
$slider_array = array(
get_template_directory()."/ocdi/sliders/main.zip",
get_template_directory()."/ocdi/sliders/main2.zip",
get_template_directory()."/ocdi/sliders/traffic.zip",
get_template_directory()."/ocdi/sliders/home4.zip",
get_template_directory()."/ocdi/sliders/home2.zip",
get_template_directory()."/ocdi/sliders/home3.zip",
get_template_directory()."/ocdi/sliders/main6.zip"
);
$slider = new RevSlider();
foreach($slider_array as $filepath){
$slider->importSliderFromPost(true,true,$filepath);
}
}
$import_kit_zip = get_parent_theme_file_path() . '/ocdi/elementor/elementor-kit.zip';
$import_export_module = \Elementor\Plugin::$instance->app->get_component( 'import-export' );
$import_settings['referrer'] = 'remote';
$import_export_module->import_kit( $import_kit_zip, $import_settings );
}
add_action( 'pt-ocdi/after_import', 'advokat_after_import_setup' );
// 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 elementor default styles
update_option('elementor_disable_color_schemes', 'yes');
update_option('elementor_disable_typography_schemes', 'yes');
//Check Custom Post Types in Elementor Setting
function advokat_custom_post_type_elementor_support() {
// Custom post types you want to enable Elementor for
$post_types = ['post', 'page', 'teams', 'services', 'portfolios', 'elementor-rshf']; // Replace with your CPT slugs
// Merge existing supported post types with your custom post types
$elementor_support = array_merge( get_option( 'elementor_cpt_support', [] ), $post_types );
// Update Elementor supported post types option
update_option( 'elementor_cpt_support', $elementor_support );
}
add_action( 'init', 'advokat_custom_post_type_elementor_support' );