SlideShare a Scribd company logo
Functions.php
                   It’s Not Just for Developers



@10up http://10up.com                             Eric A Mann @ericmann
Who’s This Guy?
•   Senior Web Engineer at 10up
•   WordPress Core Contributor
•   Plugin developer
•   Self-taught PHP dev


@10up http://10up.com             Eric A Mann @ericmann
And You Are?
•   Use WordPress
•   Want to tweak your site
•   Know a little about code
•   Don’t want to become a hard-core dev


@10up http://10up.com                Eric A Mann @ericmann
So, What’s PHP?
•   WP Core language
•   Used everywhere
•   Ugly
•   Beautiful


@10up http://10up.com   Eric A Mann @ericmann
WordPress Actions
“[H]ooks that the WordPress core launches
at specific points during execution, or when
specific events occur.” 1

• do_action()
• add_action()

@10up http://10up.com                 Eric A Mann @ericmann
WordPress Filters
“[H]ooks that WordPress launches to modify
text of various types before adding it to the
database or sending it to the browser
screen.” 1
• apply_filters()
• add_filter()
@10up http://10up.com                 Eric A Mann @ericmann
What’s Functions.php
•   Core part of your theme
•   Registers sidebars
•   Sets up special functionality
•   Lets you add plugin-like code


@10up http://10up.com               Eric A Mann @ericmann
Code Snippets
function wps_first_post_class( $classes ) {
    global $wp_query;
    if( 0 === $wp_query->current_post ) {
        $classes[] = 'first';
        return $classes;
    }
}
add_filter( 'post_class', 'wps_first_post_class' );



@10up http://10up.com                           Eric A Mann @ericmann
Manipulating WordPress
• Filters let you change output
• Actions let you add magic

• Both let you control the tool


@10up http://10up.com             Eric A Mann @ericmann
Live Examples
1. Clean up <head> output
2. Rename Posts
3. Add Pinterest to user profile




@10up http://10up.com              Eric A Mann @ericmann
Where to Find Snippets
•   Official Support Forums
•   WordPress Stack Exchange
•   WPSnipp
•   Google


@10up http://10up.com          Eric A Mann @ericmann
How to Cheat




           http://eam.me/code-snippet-plugin
@10up http://10up.com                     Eric A Mann @ericmann
Questions?



@10up http://10up.com                Eric A Mann @ericmann

More Related Content

PDF
Cain & Obenland — Episode 4
PDF
Powering Content Driven Applications with the World’s Most Popular CMS #ngconf
PDF
Application Performance Monitoring for WordPress
PPSX
John Overall at Word Camp Victoria 2011
PDF
WordPress, Schema & more
PDF
RxJS: A Beginner & Expert's Perspective - ng-conf 2017
PDF
A Practical Approach to React Native at All Things Open Conference
PPTX
Java spring mysql without hibernate(2) (1)
Cain & Obenland — Episode 4
Powering Content Driven Applications with the World’s Most Popular CMS #ngconf
Application Performance Monitoring for WordPress
John Overall at Word Camp Victoria 2011
WordPress, Schema & more
RxJS: A Beginner & Expert's Perspective - ng-conf 2017
A Practical Approach to React Native at All Things Open Conference
Java spring mysql without hibernate(2) (1)

What's hot (19)

PPTX
WordCamp Miami 2015 beginner course plugins
PDF
Client Side Applications with WP-API WordPress - WCMTL 2015
PDF
WordPress News, Views and Stuff October 2016
PPTX
Interns What Is DevOps
PPTX
Queue System and Zend\Queue implementation
PDF
WordPress updates - Why You Can't Live Without Them
PDF
Extending OnDemand with Atlassian Connect Add-ons
PDF
The Power of RxJS in Nativescript + Angular
PDF
Techical Workflow for a Startup
ODP
Send Mail
PDF
How to build Client Side Applications with WordPress and WP-API | #wcmia
PDF
WordPress for Govt Blogs & Microsites
PDF
How to Evaluate WordPress Plugins Before Activating
PPTX
Automation Zaman Now
PDF
Practical REST API
PPTX
How to submit sitemap by Ravi
PDF
New Theme Directory
ODP
5 W's of Hookin'
PPTX
API101 Workshop - APIStrat Amsterdam 2014
WordCamp Miami 2015 beginner course plugins
Client Side Applications with WP-API WordPress - WCMTL 2015
WordPress News, Views and Stuff October 2016
Interns What Is DevOps
Queue System and Zend\Queue implementation
WordPress updates - Why You Can't Live Without Them
Extending OnDemand with Atlassian Connect Add-ons
The Power of RxJS in Nativescript + Angular
Techical Workflow for a Startup
Send Mail
How to build Client Side Applications with WordPress and WP-API | #wcmia
WordPress for Govt Blogs & Microsites
How to Evaluate WordPress Plugins Before Activating
Automation Zaman Now
Practical REST API
How to submit sitemap by Ravi
New Theme Directory
5 W's of Hookin'
API101 Workshop - APIStrat Amsterdam 2014
Ad

Viewers also liked (9)

PPTX
Contributing to core
PDF
Mayo vs. Owatonna Oct 9, 2009
PDF
Social media brochure 1
DOC
Case study v7.2
PDF
Mayo Vs Winona Football Sept 18 2009
PPSX
Chicago Band Trip
PPTX
Playing nice with others
KEY
10 lessons from wal mart
PPTX
Questions you’re too afraid to ask
Contributing to core
Mayo vs. Owatonna Oct 9, 2009
Social media brochure 1
Case study v7.2
Mayo Vs Winona Football Sept 18 2009
Chicago Band Trip
Playing nice with others
10 lessons from wal mart
Questions you’re too afraid to ask
Ad

Similar to Functions.php - It's Not Just For Developers (20)

PPTX
2016 WordCamp Pittsburgh - Let's Write a Plugin
PDF
Intro to WordPress Plugin Development
PDF
Jumping Into WordPress Plugin Programming
PDF
Bending word press to your will
PPTX
Let’s write a plugin
PPTX
Building a WordPress Plugin
PDF
Creating Your First WordPress Plugin
PDF
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
PDF
Plugin development demystified 2017
PPTX
A peek into the world of WordPress plugin development
PDF
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
PDF
Write your first WordPress plugin
PDF
So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017
KEY
WordPress Bootcamp Part 2 - Extending WordPress
ODP
Best practices in WordPress Development
PDF
Getting Started with WordPress Development
KEY
CSI: WordPress -- Getting Into the Guts
PDF
My first WordPress Plugin
PPTX
Advanced Intro to Wordpress
PPT
Word press Plugins by WordPress Experts
2016 WordCamp Pittsburgh - Let's Write a Plugin
Intro to WordPress Plugin Development
Jumping Into WordPress Plugin Programming
Bending word press to your will
Let’s write a plugin
Building a WordPress Plugin
Creating Your First WordPress Plugin
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
Plugin development demystified 2017
A peek into the world of WordPress plugin development
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Write your first WordPress plugin
So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017
WordPress Bootcamp Part 2 - Extending WordPress
Best practices in WordPress Development
Getting Started with WordPress Development
CSI: WordPress -- Getting Into the Guts
My first WordPress Plugin
Advanced Intro to Wordpress
Word press Plugins by WordPress Experts

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Encapsulation theory and applications.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
cuic standard and advanced reporting.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPT
Teaching material agriculture food technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
KodekX | Application Modernization Development
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Encapsulation theory and applications.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
The AUB Centre for AI in Media Proposal.docx
NewMind AI Weekly Chronicles - August'25 Week I
cuic standard and advanced reporting.pdf
Review of recent advances in non-invasive hemoglobin estimation
Reach Out and Touch Someone: Haptics and Empathic Computing
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Teaching material agriculture food technology
Dropbox Q2 2025 Financial Results & Investor Presentation
Network Security Unit 5.pdf for BCA BBA.
KodekX | Application Modernization Development
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation_ Review paper, used for researhc scholars
Programs and apps: productivity, graphics, security and other tools
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton

Functions.php - It's Not Just For Developers

  • 1. Functions.php It’s Not Just for Developers @10up http://10up.com Eric A Mann @ericmann
  • 2. Who’s This Guy? • Senior Web Engineer at 10up • WordPress Core Contributor • Plugin developer • Self-taught PHP dev @10up http://10up.com Eric A Mann @ericmann
  • 3. And You Are? • Use WordPress • Want to tweak your site • Know a little about code • Don’t want to become a hard-core dev @10up http://10up.com Eric A Mann @ericmann
  • 4. So, What’s PHP? • WP Core language • Used everywhere • Ugly • Beautiful @10up http://10up.com Eric A Mann @ericmann
  • 5. WordPress Actions “[H]ooks that the WordPress core launches at specific points during execution, or when specific events occur.” 1 • do_action() • add_action() @10up http://10up.com Eric A Mann @ericmann
  • 6. WordPress Filters “[H]ooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen.” 1 • apply_filters() • add_filter() @10up http://10up.com Eric A Mann @ericmann
  • 7. What’s Functions.php • Core part of your theme • Registers sidebars • Sets up special functionality • Lets you add plugin-like code @10up http://10up.com Eric A Mann @ericmann
  • 8. Code Snippets function wps_first_post_class( $classes ) { global $wp_query; if( 0 === $wp_query->current_post ) { $classes[] = 'first'; return $classes; } } add_filter( 'post_class', 'wps_first_post_class' ); @10up http://10up.com Eric A Mann @ericmann
  • 9. Manipulating WordPress • Filters let you change output • Actions let you add magic • Both let you control the tool @10up http://10up.com Eric A Mann @ericmann
  • 10. Live Examples 1. Clean up <head> output 2. Rename Posts 3. Add Pinterest to user profile @10up http://10up.com Eric A Mann @ericmann
  • 11. Where to Find Snippets • Official Support Forums • WordPress Stack Exchange • WPSnipp • Google @10up http://10up.com Eric A Mann @ericmann
  • 12. How to Cheat http://eam.me/code-snippet-plugin @10up http://10up.com Eric A Mann @ericmann

Editor's Notes

  • #3: Personal IntroductionSenior Web Engineer @ 10upPreviously worked on .NetprojectsFormer freelance PHP/JS developerContributed to every major WP release since 2.3Build plugins and other custom WP code for clientsLike many of you, I’m primarily self-taught in PHP.
  • #5: PHP is one of the 5 core “languages” used in WordPress. The other four being JavaScript, MySQL, HTML, and CSS.It’s also one of the most widely used interpreted languages on the Internet because it’s preinstalled by a vast majority of web hosts.The syntax is a big ugly. PHP is open source, so there are contributions from literally hundreds of developers, all with different ideas of how to do things. Some functions are easier to understand than others. Some documentation just doesn’t make sense.But there’s also a huge community supporting it. So if something doesn’t make sense, you can probably find someone to explain it. The fact that it’s interpreted rather than compiled means we can get away with a lot of advanced hackery that wouldn’t fly elsewhere.Duck Typing lets us do some powerful and amazing things.
  • #6: What exactly is an action in WordPress? Well, it’s code that does something.Think of it as an event notification system – whenever WordPress does X, trigger any events that are listening for X to happen.Actions can pass data to listeners so they can act accordingly.
  • #7: What exactly is a filter in WordPress? Well, it’s code that filters something.Think of it as an approval system. Before doing something with data (i.e. Content), WordPress checks to see if anyone else cares about doing something to that data first and gives you the opportunity to manipulate things.Filters can pass contextual data along with the data being manipulated so you can make further decisions on it.
  • #9: This chunk of code comes in two parts:A function that does something based on passed data and the global state of WordPressA filter that applies this function to a specific data check in WordPress
  • #10: Remember, WordPress is a tool, albeit a rich one. You don’t have to fit the tool; you can manipulate the tool to fit you.
  • #11: The &lt;head&gt; element includes a lot of content that you don’t need. If you’re a Mac user, you probably don’t need the Windows Live Writer manifest in the header. If you don’t use comments, you don’t need a link to the comments feed. You can get rid of this cruft easily.If you’re building a news site, using the word “Article” might make more sense than “Post.”If you’re in to Pinterest, you might want it added to your user profile.Live Examples