copilota sordukwordpress bir eklenti yapalım bu eklenti Listele tıklayınca çok uzun başlıkları listelesin bu uzunluğu kullanıcı belirleyebilsin. kullanıcı yine kendi belileyeceği karakter kadar sadece listelenen bütün bu başlıkları kısaltabilsin. eğer kelime yarım kalıyorsa kelimeyi bozmadan sonuna da üç nokta koysunTabii ki, böyle bir WordPress eklentisi oluşturabiliriz. İşte ana işlevleri karşılayan basit bir eklenti:
Eklenti Dosyasını Oluşturun:
Bir dosya oluşturun ve adınıkoyun. İçine aşağıdaki kodu yapıştırın:Kod:Tümünü seç
custom-title-shortener.phpKod:Tümünü seç
<?php /** * Plugin Name: Custom Title Shortener * Description: Uzun başlıkları kullanıcı tarafından belirlenen uzunlukta kısaltan ve üç nokta ekleyen eklenti. * Version: 1.0 * Author: Your Name */ // Kullanıcıların başlık uzunluğunu belirleyebileceği bir ayar sayfası oluşturun function cts_add_settings_page() { add_options_page('Title Shortener Settings', 'Title Shortener', 'manage_options', 'title-shortener-settings', 'cts_render_settings_page'); } add_action('admin_menu', 'cts_add_settings_page'); function cts_render_settings_page() { ?> <div class="wrap"> <h1>Title Shortener Settings</h1> <form method="post" action="options.php"> <?php settings_fields('cts_settings_group'); do_settings_sections('cts_settings_group'); ?> <table class="form-table"> <tr valign="top"> <th scope="row">Max Title Length</th> <td><input type="number" name="cts_max_length" value="<?php echo esc_attr(get_option('cts_max_length', 50)); ?>" /></td> </tr> </table> <?php submit_button(); ?> </form> </div> <?php } // Ayarları kaydetme function cts_register_settings() { register_setting('cts_settings_group', 'cts_max_length'); } add_action('admin_init', 'cts_register_settings'); // Başlıkları kısaltma işlevi function cts_shorten_title($title) { $max_length = get_option('cts_max_length', 50); if (strlen($title) > $max_length) { $title = substr($title, 0, $max_length); $last_space = strrpos($title, ' '); if ($last_space !== false) { $title = substr($title, 0, $last_space); } $title .= '...'; } return $title; } add_filter('the_title', 'cts_shorten_title'); // Eklenti için kısa kod oluşturma function cts_list_titles() { $args = array( 'post_type' => 'post', 'posts_per_page' => -1, ); $query = new WP_Query($args); $output = '<ul>'; if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $output .= '<li>' . cts_shorten_title(get_the_title()) . '</li>'; } } $output .= '</ul>'; wp_reset_postdata(); return $output; } add_shortcode('list_titles', 'cts_list_titles');Eklentiyi Etkinleştirin:
custom-title-shortener.php dosyasını WordPress sitenizin wp-content/plugins dizinine yükleyin. WordPress yönetici paneline gidin ve "Eklentiler" bölümünden eklentiyi etkinleştirin.
Ayarları Yapın:
WordPress yönetici panelinde "Ayarlar" > "Title Shortener" sayfasına gidin ve başlıkların maksimum uzunluğunu ayarlayın.
Kısa Kodu Kullanma:
Başlıkları listelemek ve kısaltmak için herhangi bir yazı veya sayfaya şu kısa kodu ekleyin:Kod:Tümünü seç
[list_titles]
wordpress uzun başlıkları kısaltma eklentisi
wordpress uzun başlıkları kısaltma eklentisi
Re: wordpress uzun başlıkları kısaltma eklentisi
yol ayarlar>tittle shortener
Re: wordpress uzun başlıkları kısaltma eklentisi
eklenti direk tüm sitede çalıştı. ancak şöyle yapalım sadece [list_titles] kodu olan yazılarda çalışsın. tüm sistemde değil.
Tamam, yalnızca [list_titles] kısa kodunun kullanıldığı yerlerde çalışacak şekilde kodumuzu düzenleyelim. Aşağıdaki güncellenmiş kod, yalnızcakısa kodunun kullanıldığı sayfalarda başlıkları kısaltacaktır.Kod:Tümünü seç
[list_titles]
Güncellenmiş Eklenti Dosyası:
Kod:Tümünü seç
<?php /** * Plugin Name: Custom Title Shortener * Description: Uzun başlıkları kullanıcı tarafından belirlenen uzunlukta kısaltan ve üç nokta ekleyen eklenti. * Version: 1.1 * Author: Your Name */ // Kullanıcıların başlık uzunluğunu belirleyebileceği bir ayar sayfası oluşturun function cts_add_settings_page() { add_options_page('Title Shortener Settings', 'Title Shortener', 'manage_options', 'title-shortener-settings', 'cts_render_settings_page'); } add_action('admin_menu', 'cts_add_settings_page'); function cts_render_settings_page() { ?> <div class="wrap"> <h1>Title Shortener Settings</h1> <form method="post" action="options.php"> <?php settings_fields('cts_settings_group'); do_settings_sections('cts_settings_group'); ?> <table class="form-table"> <tr valign="top"> <th scope="row">Max Title Length</th> <td><input type="number" name="cts_max_length" value="<?php echo esc_attr(get_option('cts_max_length', 50)); ?>" /></td> </tr> </table> <?php submit_button(); ?> </form> </div> <?php } // Ayarları kaydetme function cts_register_settings() { register_setting('cts_settings_group', 'cts_max_length'); } add_action('admin_init', 'cts_register_settings'); // Başlıkları kısaltma işlevi function cts_shorten_title($title) { $max_length = get_option('cts_max_length', 50); if (strlen($title) > $max_length) { $title = substr($title, 0, $max_length); $last_space = strrpos($title, ' '); if ($last_space !== false) { $title = substr($title, 0, $last_space); } $title .= '...'; } return $title; } // Eklenti için kısa kod oluşturma function cts_list_titles() { $args = array( 'post_type' => 'post', 'posts_per_page' => -1, ); $query = new WP_Query($args); $output = '<ul>'; if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $output .= '<li>' . cts_shorten_title(get_the_title()) . '</li>'; } } $output .= '</ul>'; wp_reset_postdata(); return $output; } add_shortcode('list_titles', 'cts_list_titles'); // Yalnızca list_titles kısa kodu kullanıldığı yerde başlıkları kısaltma function cts_maybe_shorten_title($title) { if (has_shortcode(get_post_field('post_content', get_the_ID()), 'list_titles')) { return cts_shorten_title($title); } return $title; } add_filter('the_title', 'cts_maybe_shorten_title');
Re: wordpress uzun başlıkları kısaltma eklentisi
buradaki kod başlıkları kısaltıyor ama yazıyı tıklayınca yazının normal görünmesi gerekiyor
bu eski kod yani heryerde kısaltma yapıyor:Kod:Tümünü seç
<?php /** * Plugin Name: Custom Title Shortener * Description: Uzun başlıkları kullanıcı tarafından belirlenen uzunlukta kısaltan ve üç nokta ekleyen eklenti. * Version: 1.0 * Author: Your Name */ // Kullanıcıların başlık uzunluğunu belirleyebileceği bir ayar sayfası oluşturun function cts_add_settings_page() { add_options_page('Title Shortener Settings', 'Title Shortener', 'manage_options', 'title-shortener-settings', 'cts_render_settings_page'); } add_action('admin_menu', 'cts_add_settings_page'); function cts_render_settings_page() { ?> <div class="wrap"> <h1>Title Shortener Settings</h1> <form method="post" action="options.php"> <?php settings_fields('cts_settings_group'); do_settings_sections('cts_settings_group'); ?> <table class="form-table"> <tr valign="top"> <th scope="row">Max Title Length</th> <td><input type="number" name="cts_max_length" value="<?php echo esc_attr(get_option('cts_max_length', 50)); ?>" /></td> </tr> </table> <?php submit_button(); ?> </form> </div> <?php } // Ayarları kaydetme function cts_register_settings() { register_setting('cts_settings_group', 'cts_max_length'); } add_action('admin_init', 'cts_register_settings'); // Başlıkları kısaltma işlevi function cts_shorten_title($title) { $max_length = get_option('cts_max_length', 50); if (strlen($title) > $max_length) { $title = substr($title, 0, $max_length); $last_space = strrpos($title, ' '); if ($last_space !== false) { $title = substr($title, 0, $last_space); } $title .= '...'; } return $title; } add_filter('the_title', 'cts_shorten_title'); // Eklenti için kısa kod oluşturma function cts_list_titles() { $args = array( 'post_type' => 'post', 'posts_per_page' => -1, ); $query = new WP_Query($args); $output = '<ul>'; if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $output .= '<li>' . cts_shorten_title(get_the_title()) . '</li>'; } } $output .= '</ul>'; wp_reset_postdata(); return $output; } add_shortcode('list_titles', 'cts_list_titles');buda cgpt
bu tamam görünüyor
Kod:Tümünü seç
<?php /** * Plugin Name: Custom Title Shortener * Description: Uzun başlıkları kullanıcı tarafından belirlenen uzunlukta kısaltan ve üç nokta ekleyen eklenti. Tekil yazı sayfasında tam başlık gösterilir. * Version: 1.1 * Author: Your Name */ // Ayar sayfası ekleme function cts_add_settings_page() { add_options_page('Title Shortener Settings', 'Title Shortener', 'manage_options', 'title-shortener-settings', 'cts_render_settings_page'); } add_action('admin_menu', 'cts_add_settings_page'); // Ayar sayfasını render etme function cts_render_settings_page() { ?> <div class="wrap"> <h1>Title Shortener Settings</h1> <form method="post" action="options.php"> <?php settings_fields('cts_settings_group'); do_settings_sections('cts_settings_group'); ?> <table class="form-table"> <tr valign="top"> <th scope="row">Max Title Length</th> <td> <input type="number" name="cts_max_length" value="<?php echo esc_attr(get_option('cts_max_length', 50)); ?>" /> </td> </tr> </table> <?php submit_button(); ?> </form> </div> <?php } // Ayarları kaydetme function cts_register_settings() { register_setting('cts_settings_group', 'cts_max_length'); } add_action('admin_init', 'cts_register_settings'); // Başlıkları kısaltma işlevi function cts_shorten_title($title) { // Yönetim panelinde veya tekil yazı sayfasında tam başlık göster if ( is_admin() || is_single() ) { return $title; } $max_length = get_option('cts_max_length', 50); if (strlen($title) > $max_length) { $title = substr($title, 0, $max_length); $last_space = strrpos($title, ' '); if ($last_space !== false) { $title = substr($title, 0, $last_space); } $title .= '...'; } return $title; } add_filter('the_title', 'cts_shorten_title'); // Yazıları listelemek için kısa kod function cts_list_titles() { $args = array( 'post_type' => 'post', 'posts_per_page' => -1, ); $query = new WP_Query($args); $output = '<ul>'; if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $output .= '<li>' . cts_shorten_title(get_the_title()) . '</li>'; } } $output .= '</ul>'; wp_reset_postdata(); return $output; } add_shortcode('list_titles', 'cts_list_titles'); ?>