WordPress Özel Tema>

1 Cevap php

Ben kalıcı bağlantı setleri ve tema tarafından kullanılan kategoriler ekliyor benim functions.php dosyasına bazı kurulum kodu var. Ben sadece tema ilk devreye girdiğinde bu kod çalıştırmak istiyorum. Tekrar çalıştırmak için kodu için gerek yoktur. Ancak, functions.php dosyasına koyarak, bu web sitesinde her ve her seferinde bir sayfa çalışır yüklenir.

Özel tema ilk devreye girdiğinde bu kod yalnızca çalışır, böylece kullanmak için alternatif bir yöntem var mı?

1 Cevap

In wp-includes/theme.php Eğer işlevini bulacaksınız switch_theme(). Bu bir eylem kanca sunar:

/**
 * Switches current theme to new template and stylesheet names.
 *
 * @since unknown
 * @uses do_action() Calls 'switch_theme' action on updated theme display name.
 *
 * @param string $template Template name
 * @param string $stylesheet Stylesheet name.
 */
function switch_theme($template, $stylesheet) {
    update_option('template', $template);
    update_option('stylesheet', $stylesheet);
    delete_option('current_theme');
    $theme = get_current_theme();
    do_action('switch_theme', $theme);
}

Yani functions.php bu kullanabilirsiniz:

function my_activation_settings($theme)
{
    if ( 'Your Theme Name' == $theme )
    {
        // do something
    }
    return;
}
add_action('switch_theme', 'my_activation_settings');

Sadece bir fikir; Ben henüz denemedim.