Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Kupası
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

WordPress Özel Yazı Türleri Tartışması – Functions.php mi Eklentiler mi?

Editoryal Not: WPBeginner üzerindeki ortak bağlantılardan komisyon kazanıyoruz. Komisyonlar, editörlerimizin görüşlerini veya değerlendirmelerini etkilemez. Editoryal Süreç hakkında daha fazla bilgi edinin.

Birçoğunuzun bildiği gibi, geçtiğimiz hafta Syed Balkhi WordCamp Raleigh 2012’ye katıldı. Etkinlik sırasında attığı tweetlerden biri büyük bir tartışmaya yol açtı. Bu makalede, kurucumuz Syed Balkhi WordPress Özel Yazı Tiplerinin functions.php dosyasına mı yoksa eklentilere mi ait olduğunu tartışacak. Aşağıda bu tartışmayı başlatan tweet yer almaktadır:

Tweet’in ardından WordPress topluluğundaki pek çok saygın kişi görüşlerini paylaştı. Konuşmanın tamamını burada görebilirsiniz. Curtis McHale konuyu bir adım daha ileri götürdü ve yeni blog yazısında konuyu detaylandırdı.

Twitter’daki sohbet bazı harika noktaları gündeme getirdi.

Argümanların Özeti

Eklentiler argümanı: Kullanıcı temayı değiştirse bile verilere her zaman sahip olacaktır. O kadar güzel görünmeyebilir ama orada kalacaktır.

Functions.php Argüman: Tasarım olmadan veri alakasız olacaktır. Kullanıcıların kafasını daha da karıştıracaktır.

Hangi tarafa daha çok katılıyorsunuz? Açıkçası her iki tarafın da sorunları var, ama hangisi kötünün iyisi?

İşte bu nedenle Özel Yazı Türlerinin DAİMA siteye özel bir eklentide veya tamamen ayrı bir eklentide bulunması gerektiğine inanıyoruz.

Çok Yaşa Veri

Özel Yazı Türleri birer veridir. Çoğu durumda verileriniz mevcut tasarımdan daha uzun ömürlü olacaktır. Temalarımızı birkaç kez değiştirdiğimiz için bu ifadeyi net bir şekilde anlıyoruz. Yazılar, Sayfalar, Bağlantılar, Ekler ve Revizyonlar WordPress ile yerleşik olarak gelen tüm yazı türleridir. Bunun da ötesinde, Kitaplar, Görüşler, Fırsatlar vb. gibi yazı türlerimiz de var. Şimdi bir tema değiştirdiğimizi ve tüm bunların kaybolduğunu hayal edebiliyor musunuz? Elbette bunun olmasını istemeyiz.

Ekibimizde geliştiriciler olduğu için bunun çok da önemli olmaması gerekir. Tüm temalarımızın ekibimiz tarafından özel olarak tasarlandığını düşünürsek, gerçekten ne fark eder? İşin sırrı iki kelimede yatıyor: zaman ve merkezileştirme. Gerekli tüm verilere sahip olduğumuz sürece, gelecekte yapmamız gereken tek şey stilleri değiştirmek olacaktır. Her seferinde fonksiyonları bir dosyadan diğerine kopyalayıp yapıştırma konusunda endişelenmemize gerek kalmayacak. Peki ya işlevselliği çoğaltmak isterseniz? Basitçe eklentiyi alın ve yeni sitenize bırakın. Şekillendirmeyi değiştirin ve işiniz bitti.

Kurallar ve Standartlar

Tweetimizde yaptığımız gibi ALWAYS kelimesini kullandığınızda, bu hem kural hem de standart anlamına gelebilir. Hem kurallar hem de standartlar çoğunluk içindir. Kuralların esnetildiği ve standartların çiğnendiği özel durum senaryoları her zaman olacaktır, ancak bu standartlardan tamamen kurtulmamız gerektiği anlamına gelmez.

Çoğunlukla aynı ek meta alan setini gerektiren tonlarca genel gönderi türü vardır. Akla gelen bazı örnekler şunlar olabilir: Alıntılar, Kitaplar, Tarifler, Görüşler, Portföy vb.

Ücretsiz ve ticari pazarda bulunan çok sayıda fotoğrafçılık ve portföy teması düşünüldüğünde, kullanıcının her tema değiştirdiğinde tüm özel gönderi türü bilgilerini yeniden girmesini sağlamak neredeyse hiç mantıklı değildir. Örnek bir vaka senaryosuna göz atalım:

Fotoğrafçı – Kullanıcı blog işlevine sahip bir WordPress kurdu (varsayılan “gönderi” CPT’si). Çalışmalarının bir portföyünü eklemek istiyor (bir Portföy CPT’si gerektirir). Müşteri referanslarını göstermek istiyor (bir Testimonial CPT gerektirir). Tüm bu bilgiler kesinlikle bir tema tasarımının ötesinde yaşayacaktır. Bir yıl sonra kullanıcı sitesinin görünümünü değiştirmek ve yenilemek istiyor. Tüm benzer işlevlere sahip yeni bir tema bulur. Temayı değiştirdiği anda, BOOM. Girdiği tüm önceki veriler kaybolmuştur. Portföy adında bir menü ve Görüşler adında bir menü var ancak verilerin hiçbiri orada değil. Kullanıcı “HOLY CRAP, tüm içeriğimi kaybettim” diye düşünür. Forumda yeni bir destek sorusu oluşturur. WPBeginner vb. gibi sitelere e-posta gönderir. İyi bir yanıt alamazlarsa, tüm verileri yeniden girmek zorunda kalacaklar. Bu berbat bir kullanıcı deneyimidir.

Peki bu sorunu nasıl çözeceğiz?

Olası Çözüm?

Yeni bir standart taban oluşturuyoruz. Justin Tadlock bir süre önce bir temel portföy eklentisi oluşturarak bu konu üzerinde çalışmaya başladı bile. Bu herkes için mükemmel bir çözüm olacak mı? HAYIR, ama çoğunluk için olacak.

Justin’in yazısında sorduğu gibi, portföy eklentisine hangi standart alanlar dahil edilmelidir (yazı metasına atıfta bulunarak). Bu tür bir konuşmanın, temalarında benzer işlevler yaratan geliştiriciler arasında gerçekleşmesi gerekiyor. Bir eklenti aracılığıyla yapılabilecekken neden aynı şeyi bir temadan diğerine tekrar tekrar kopyalayıp yapıştıralım? Bu bir standart haline geldiğinde, diğer tema yazarları da buna uyum sağlamaya başlayacaktır.

Örneğin, Genesis ve diğerleri gibi WordPress tema çerçevelerinde Gravity Forms için stil desteğinde bir artış görüyoruz. Neden mi? Çünkü kullanıcılarının bunu kullandığını anlıyorlar.

Eklenti olması gerektiğine inandığımız işlevselliklerle yüklü olarak gelen bazı sağlam WordPress temaları vardır. İş Kurulu temaları, Sorun İzleme temaları, Sınıflandırılmış Reklam teması, Emlak Temaları vb. Hepsi bir temel eklenti tarafından desteklenmelidir. WooCommerce ile bu zaten gerçekleşiyor. WooThemes, eklenti için yerleşik stil desteğine sahip çok sayıda tema yayınladı. Diğer tema şirketleri de WooCommerce tabanlı e-ticaret temaları yayınlama sözü verdi. Bir temadan diğerine geçebilir ve tüm ürünlerinizi olduğu gibi tutabilirsiniz. Sanki tema değişmiş ama her şey yerli yerine oturmuş gibi. İşte bunun için çabalamamız gereken tema değiştirme deneyimi budur.

Aynı şeyi Portföy, Görüşler ve diğer genel özel gönderi türleri için neden yapmıyorsunuz? Bunun nedeni çok basit olması ve e-ticaretin fethedilmesi gereken daha büyük bir canavar olması mı? Açıkçası, e-Ticaret diğerlerine kıyasla çok fazla alana sahiptir, bu nedenle bu genel gönderi türleri için çok daha kolay olmalıdır. Bu sadece işleri daha iyi hale getirmek için bilinçli bir çaba gösterme meselesidir.

ReciPress eklentisine bir göz atın. Tarif alanları ile özel bir metabox oluşturur ve bunu yazılara ekler. Ancak özel yazı türlerine de eklemek mümkün. Bu eklentiyi kullanan herkes, böyle bir güçlükle uğraşmak zorunda kalmadan temaları değiştirebilir.

AgentPress gibi temaların merkezi bir temel eklenti tarafından desteklendiğini görmek güzel olurdu. Tema değiştirmenin daha kolay hale geldiğini görmek harika olurdu. Örneğin, bir kullanıcı bir fotoğrafçılık temasından diğerine geçerse, bu kaos olmamalıdır. Küçük hatalar olabilir, ancak en azından büyük resimde işler yürüyecektir.

Tek seferlik müşteri kullanımı için oluşturulan süper özelleştirilmiş gönderi türlerine her zaman örnek verebilirsiniz, ancak bu kural değil istisnadır.

Siz bu konu hakkında ne düşünüyorsunuz? Özel yazı türleri kodu nerede bulunmalıdır? functions.php dosyasında mı yoksa eklentilerde mi?

Açıklama: İçeriğimiz okuyucu desteklidir. Bu, bazı bağlantılarımıza tıklarsanız komisyon kazanabileceğimiz anlamına gelir. WPBeginner'ın nasıl finanse edildiğini, neden önemli olduğunu ve nasıl destek olabileceğinizi görün. İşte editoryal sürecimiz.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

Ultimate WordPress Araç Kiti

Araç setimize ÜCRETSİZ erişim sağlayın - her profesyonelin sahip olması gereken WordPress ile ilgili ürün ve kaynaklardan oluşan bir koleksiyon!

Reader Interactions

34 yorumBir Cevap Bırakın

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Yazmin says

    Having been on the end of losing my CPTs numerous times as I switched themes, I find it frustrating to have to set up the same functionality over and over again in functions.php.

    I completely prefer the plugin route and that is the method I will be using from here on out for my business projects as well.

  3. Joshua Jarvis says

    Having this exact issue with a real estate theme. The “listings” were all custom types in a theme that is now functionally obsolete. When I went to upgrade the theme I lost all the custom post content, now I have to figure out a way to transfer it all. I have options, but if it were plugin, this wouldn’t be necessary.

  4. Hugh H. Sands says

    “We won’t have to worry about copying and pasting the functions from one file to another every single time.”
    I can’t imagine someone writing code for a CPT in functions.php when it’s so easy to isolate it with includes

    This debate goes most of the times around data vs design and I wonder, being quite new to WP, what about performance? Do plugins impose any overload?

  5. Kelvin Alfonso says

    I’ve always included CPT’s through a separate file into the functions.php but I think I’ll be switching over to the plugins route. Thank you!

  6. Sudhakar says

    I am a beginner and I have no expertise to comment one way or the other in favor or against of a plug-in or functions.php. But I am wondering if I want to go the functions.php route and do it under a child theme, what is the problem then? Why do I need to have it in a plug-in, wouldn’t my child theme save me from future theme upgrades and changes in the themes?

    • Editorial Staff says

      Your child theme would save you from future theme updates. However, it will NOT save you if you change your themes. Because you change the child theme if you change the active theme.

      Yönetici

  7. Pat Ramsey says

    I’m a believer in the plugin route for custom post types & taxonomies. The author’s mention of a site-specific plugin is how I do it. I place any custom post types, custom taxonomies & metaboxes in this plugin, tailored for the site’s purpose. Eventually the site’s theme will change but the data lives on & is still easily accessible.

  8. shawn says

    If developers continue to ignore the fact that separating “data” from for “design” is necessary to create modular apps, and it does not matter where it is the data placed, reusing that data / code will always be problem.

    There seems to be a perception by some in the WP community, for one reason or the other that you can only access data in the WordPress ecosystem if it is wrapped in a plugin so we keep seeing discussions like this contributing to “The great plugin vs theme debate”.

    Focus needs to placed on evolving the WordPress’ archaic plugin system, to creating libraries based on a modular design patterns that separate code / data from design. Libraries that can be used in both themes and plugins….

    Debates like these are pointless in the WP post PHP4 era!!! (re-post)

  9. Mark Simchock says

    Re: “As Justin asks in his post, what standard fields should be included in the portfolio plugin (referring to post meta). This type of conversation needs to happen among developers who are creating similar functionality in their themes.”

    Moi? I would prefer a well documented plugin that’s engineered to be enhanced than a “closed”, one size fits all approach that difficult to work with (that code).

    My point is, perhaps it’s possible to say, “I’m not trying to be all things to all people. Here’s my basic plugin. Here’s how you trick it out. It’s designed to be tricked out.” and just leave it at that. No matter what you do it’s difficult to anticipate every use case, every use need. So why bother? Why not approach it as a framework (of sorts) and let the dev in need just customize as needed?

    • Justin Tadlock says

      That’s actually the plan. I’m building an extremely small and easily-customizable base. But, I’d like to know what, if any, fields should be standard.

  10. Affan Ruslan says

    I believe it should be on plugin.
    In case the user might not need the data in future, they can always convert the custom post type post to the “normal” post type. There’s plugin to do so, search in the repo and you’ll find at least one.

  11. Christophe Debruel says

    I don’t really care what people say. Custom post type goes into a plugin. A theme can easily be modified to fit the custom post type in the frontend. I find it more logic to style the theme for the CTP than having different themes with the same CTP code.

  12. Elliott Richmond says

    Plugin for me. At least for a non technical client, although the theme might not function correctly it will become apparent that there is a problem and that will prompt them to get a developer onboard.

  13. Kailas Mahajan says

    Its all depend on the project…
    if one handling project which needs to change theme after a certaine period of time…can use plugin..

    or if project which are sticking with the one theme.. can go with function.php

  14. Ross W says

    Everyone’s talking about how the data needs to be styled by the theme, and examples where that’s the case and where the data and theme can be separated.

    What I don’t see is anyone talking about cases where a theme depends on having some specific data available. Lets say you have a theme that has a map of countries and some country-specific data, and that, without that map and data the theme loses some of its key functionality.

    Yes, you could still do this with the data in a plugin, but is it reasonable for a theme to assume that some data exists? Is it reasonable to assume that the plugin that creates the data types is installed and enabled? (Genuine questions…discuss!)

    What if my slightly non-technical client wants to create a copy of the site with their ‘theme’. They enable the theme on a new WordPress install only to find that a whole load of stuff is missing or broken? They thought that the theme contained all that they needed for their site to look right?

    I can see uses for both approaches. For most of my client work I set up CPT’s, meta-boxes, and some functions to make accessing them simple, in library files and include them. This keeps all the ‘stuff’ that my theme needs to work in one package, but keeps it simple to move the CPT’s to a new theme should I want to.

    Of course, if a CPT looks like it could be used across multiple themes and isn’t SO specific that it only really applies to a single client’s data then you turn it into a plugin that can be deployed at will.

    I don’t think there’s a simple, one-way relationship between data and themes. It’s not always the case that ‘I have some data that needs styling’…sometimes ‘my styling needs some data’.

    Thoughts on that?

    • Andres Hermosilla says

      I definitely agree that there is a benefit to having one “complete” package. Often times there is very theme specific functionality that is better to be tied in directly (i.e. P2 from Auttomatic) vs. installed theme and theme plugin.

  15. Curtis McHale says

    Your reference to AgentPress is one of the reasons I’m 100% for CPT’s in plugins. I’ve had to deal with themes like that and it’s so hard to skin them properly unless you remove the custom function from the theme. My client and I spent 20 hours getting the code to a point we could actually work on it.

      • Birgit says

        The plugin is a “toolbox” for code snippets, that you do normally in your functions.php.
        But with a theme update, custom code in the theme’s function.php might get lost.
        So I use within my network installation this plugin, activated it network-wide and then the plugin comes with “modules”, that you can access for example by FTP.
        You can create modules as much as you like – I have one for each of my blogs within this network. In this modules (= just .php files, let’s say just like site-specific plugins) you can add all the code, that you normally put in your theme’s function.php.
        Then at the options page of the plugin you can activate in each blog, which module you would like to load and whether to load it only for frontend or only for backend or for both.
        So I only need to have 1 plugin to serve all blogs with individual code snippets, that normally go to their functions.php – and can decide, where to load these modules.
        uff, hope this is understandable, because my English is not the best ;-)

        Perhaps this will work for you to read it: http://tinyurl.com/bf5dflt

        • Editorial Staff says

          Brigit, I did translate the WP.org page as well. I understood what the plugin was intended for. However the screenshots were in German, and google is not smart enough to translate images just yet. Same issue is with the link you posted :)

  16. Sara says

    I always prefer plugins over functions.php for anything that would materially “break” on the front end or lose data if the theme were changed. This is for precisely the reasons you cite, and I also feel that it is NUTSO for those of us who are not really php programmers to try to troubleshoot conflicts when you have to be commenting out stuff in functions.php to isolate a problem.

    • Editorial Staff says

      The idea is that you should register CPT’s in a site-specific plugin. There is not a specific plugin out there yet. But this is just tossing around the idea of creating a base plugin for generic post types.

      Yönetici

  17. Muhammad Waqas says

    I’m more convinced with the use of local functions. but in this case I think plugin can be trusted more. For example if you start using wp with a specific framework. In most of cases It possible that you’ll become a slave for a long time unless until you hire a wp professional to help you escape from that framework without losing your settings and data. On the other hand plugins can work at almost at every theme.

    When I started working with wp I preferred framework over plugin. The reality is that plugin developer consider newbie and less literate people when developing something. I personally believe that most part of wp users like manual code hacks than depending on plugins for core functions of sites. in long term plugins aren’t reliable. I fee so..

Bir Cevap Bırakın

Yorum bırakmayı seçtiğiniz için teşekkür ederiz. Lütfen tüm yorumların yorum poli̇ti̇kasi uyarınca denetlendiğini ve e-posta adresinizin yayımlanmayacağını unutmayın. Ad alanında anahtar kelime KULLANMAYIN. Kişisel ve anlamlı bir sohbet edelim.