![](/img/trans.png)
[英]Customize the Wordpress Divi Theme functions.php contact form
[英]What do I need to add to the functions.php file inside my Divi child theme
我的問題是:我需要將哪些內容添加到Divi子主題中的functions.php
文件中。
我想在Divi Builder的“字體選擇器”中添加新的Google字體(Varela Round)。
我知道該怎么做。 所以這不是我的問題。
1)在Divi中添加“ webfont”文件夾2)在header.php中,我需要在關閉head標簽之前:
<link rel="stylesheet" href="<?php echo $template_directory_uri; ?>/webfonts/stylesheet.css" type="text/css" charset="utf-8">
比我需要添加兩個文件:
themes/Divi/includes/builder/core.php
themes/Divi/epanel/custom_functions.php
下一行:
$google_fonts = array(
'Varelda Round' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'sans-serif',
),
當我在Divi主題中執行此操作時,可以從Divi的“字體選擇器”中選擇“ Varela Round”字體
我現在遇到的問題是將所有這些翻譯成我的Divi兒童主題。
在我的Divi子主題中,我添加了帶有字體的“ webfont”文件夾。
在Divi子主題中,我創建了以下兩個結構。
includes/builder/core.php
epanel/custom_functions.php
我從父Divi主題中刪除了core.php
和custom_functions.php
。
我知道我仍然需要從子主題更改我的functions.php
某些內容,但這就是我遇到的問題。 我不知道我需要在子主題functions.php
您可以在下面找到子主題functions.php
文件,因為我已經進行了一些自定義。
<?php
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
//wp_enqueue_script( 'parent-script', get_template_directory_uri().'/js/main.js' );
}
add_action("wp_head","fun_head");
function fun_head()
{
if (is_user_logged_in()) {
global $current_user;
get_currentuserinfo();
$candi="none";
$comp="none";
if ( isset( $current_user->roles ) && is_array( $current_user->roles ) )
{
//check for admins
if ( in_array( 'candidate', $current_user->roles ) )
{
// redirect them to the default place
$candi="block";
}
elseif(in_array( 'employer', $current_user->roles ))
{
$comp="block";
}
}
?>
<style type="text/css">
#show_logut {
display: block;
}
#show_myaccountcandi
{
display: <?php echo $candi; ?>;
}
#show_myaccountcomp
{
display: <?php echo $comp; ?>;
}
#show_login {
display: none ;
}
#show_signup {
display: none ;
}
</style>
<?php }
else { get_template_part('ajax', 'auth');
//include('ajax-auth.php');
?>
<style type="text/css">
#show_logut {
display: none;
}
#show_myaccountcandi
{
display: none;
}
#show_myaccountcomp
{
display: none;
}
#show_login {
display: block;
}
#show_signup {
display: block ;
}
</style>
<?php }
}
require_once(WP_CONTENT_DIR. '/themes/divichild/custom-ajax-auth.php' );
add_action( 'template_redirect', 'wpse8170_activate_user' );
function wpse8170_activate_user() {
if ( is_page() && get_the_ID() == 25462 ) {
$user_id = filter_input( INPUT_GET, 'user', FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1 ) ) );
if ( $user_id ) {
// get user meta activation hash field
$code = get_user_meta( $user_id, 'has_to_be_activated', true );
if ( $code == filter_input( INPUT_GET, 'key' ) ) {
delete_user_meta( $user_id, 'has_to_be_activated' );
update_user_meta($user_id,"activated",1);
$user = get_user_by( 'id', $user_id );
if( $user ) {
wp_set_current_user( $user_id, $user->user_login );
wp_set_auth_cookie( $user_id );
do_action( 'wp_login', $user->user_login, $user);
echo "Please wait until process complete.";
//echo get_option("siteurl")."/mijn-account";
wp_redirect(get_option("siteurl")."/mijn-account");
exit();
}
}
}
echo "<strong>Activation Key is wrong or expired.</strong>";
die();
}
}
function my_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
if ( isset( $user->roles ) && is_array( $user->roles ) )
{
//check for admins
if ( in_array( 'candidate', $user->roles ) )
{
// redirect them to the default place
return get_option("siteurl")."/candidate-dashboard";
}
elseif(in_array( 'employer', $user->roles ))
{
return get_option("siteurl")."/vacature-dashboard";
}
else
{
return home_url();
}
}
else
{
return $redirect_to;
}
}
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
add_action('wp_logout','logout_redirect');
function logout_redirect(){
wp_redirect( home_url() );
exit;
}
?>
對於任何需要此功能的人。
解決方案非常簡單...
在子主題的functions.php中,您所需要做的就是添加此內容
// Add Custom Google Font
function add_new_google_font($google_fonts) {
$new_fonts = array(
'Varela Round' => array(
'styles' => '400,400italic,700,700italic',
'character_set' => 'latin',
'type' => 'sans-serif',
),
);
return array_merge($google_fonts, $new_fonts);
}
add_filter( 'et_builder_google_fonts', 'add_new_google_font' );
add_filter( 'et_google_fonts', 'add_new_google_font' );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.