SlideShare uma empresa Scribd logo
1 de 13
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

Mais conteúdo relacionado

Mais procurados

Client Side Applications with WP-API WordPress - WCMTL 2015
Client Side Applications with WP-API WordPress - WCMTL 2015Client Side Applications with WP-API WordPress - WCMTL 2015
Client Side Applications with WP-API WordPress - WCMTL 2015
Roy Sivan
 
Extending OnDemand with Atlassian Connect Add-ons
Extending OnDemand with Atlassian Connect Add-onsExtending OnDemand with Atlassian Connect Add-ons
Extending OnDemand with Atlassian Connect Add-ons
colleenfry
 
WordPress for Govt Blogs & Microsites
WordPress for Govt Blogs & MicrositesWordPress for Govt Blogs & Microsites
WordPress for Govt Blogs & Microsites
Kristy Fifelski
 

Mais procurados (20)

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

Destaque (9)

Contributing to core
Contributing to coreContributing to core
Contributing to core
 
Mayo vs. Owatonna Oct 9, 2009
Mayo vs. Owatonna Oct 9, 2009Mayo vs. Owatonna Oct 9, 2009
Mayo vs. Owatonna Oct 9, 2009
 
Social media brochure 1
Social media brochure 1Social media brochure 1
Social media brochure 1
 
Case study v7.2
Case study v7.2Case study v7.2
Case study v7.2
 
Mayo Vs Winona Football Sept 18 2009
Mayo Vs Winona Football Sept 18 2009Mayo Vs Winona Football Sept 18 2009
Mayo Vs Winona Football Sept 18 2009
 
Chicago Band Trip
Chicago Band TripChicago Band Trip
Chicago Band Trip
 
Playing nice with others
Playing nice with othersPlaying nice with others
Playing nice with others
 
10 lessons from wal mart
10 lessons from wal mart10 lessons from wal mart
10 lessons from wal mart
 
Questions you’re too afraid to ask
Questions you’re too afraid to askQuestions you’re too afraid to ask
Questions you’re too afraid to ask
 

Semelhante a Functions.php - It's Not Just For Developers

Phpworks enterprise-php-1227605806710884-9
Phpworks enterprise-php-1227605806710884-9Phpworks enterprise-php-1227605806710884-9
Phpworks enterprise-php-1227605806710884-9
PrinceGuru MS
 

Semelhante a Functions.php - It's Not Just For Developers (20)

Building a WordPress Plugin
Building a WordPress PluginBuilding a WordPress Plugin
Building a WordPress Plugin
 
Word press interview question and answer tops technologies
Word press interview question and answer   tops technologiesWord press interview question and answer   tops technologies
Word press interview question and answer tops technologies
 
WordPress Security & Backup
WordPress Security & Backup WordPress Security & Backup
WordPress Security & Backup
 
Everything WordPress
Everything WordPressEverything WordPress
Everything WordPress
 
WordPress
WordPressWordPress
WordPress
 
Writing Your First Plugin
Writing Your First PluginWriting Your First Plugin
Writing Your First Plugin
 
Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress Applications
 
Magento 2 Best Practice Workfow // David Lambauer // Meet Magento 2017 // Lei...
Magento 2 Best Practice Workfow // David Lambauer // Meet Magento 2017 // Lei...Magento 2 Best Practice Workfow // David Lambauer // Meet Magento 2017 // Lei...
Magento 2 Best Practice Workfow // David Lambauer // Meet Magento 2017 // Lei...
 
Things you should know about WordPress (but were always too afraid to ask): W...
Things you should know about WordPress (but were always too afraid to ask): W...Things you should know about WordPress (but were always too afraid to ask): W...
Things you should know about WordPress (but were always too afraid to ask): W...
 
Most widely used WordPress tips and tricks of 2016
Most widely used WordPress tips and tricks of 2016Most widely used WordPress tips and tricks of 2016
Most widely used WordPress tips and tricks of 2016
 
WordPress Security and Best Practices
WordPress Security and Best PracticesWordPress Security and Best Practices
WordPress Security and Best Practices
 
Wordpress beyond blogging
Wordpress beyond bloggingWordpress beyond blogging
Wordpress beyond blogging
 
Demystifying WordPress
Demystifying WordPressDemystifying WordPress
Demystifying WordPress
 
&lt;?php + WordPress
&lt;?php + WordPress&lt;?php + WordPress
&lt;?php + WordPress
 
Phpworks enterprise-php-1227605806710884-9
Phpworks enterprise-php-1227605806710884-9Phpworks enterprise-php-1227605806710884-9
Phpworks enterprise-php-1227605806710884-9
 
From WordPress With Love
From WordPress With LoveFrom WordPress With Love
From WordPress With Love
 
Getting Started with WordPress Development
Getting Started with WordPress DevelopmentGetting Started with WordPress Development
Getting Started with WordPress Development
 
Your Site Has Been Hacked, Now What?
Your Site Has Been Hacked, Now What?Your Site Has Been Hacked, Now What?
Your Site Has Been Hacked, Now What?
 
Owning word press all you need to know as a wordpress developer by lutaaya ...
Owning word press   all you need to know as a wordpress developer by lutaaya ...Owning word press   all you need to know as a wordpress developer by lutaaya ...
Owning word press all you need to know as a wordpress developer by lutaaya ...
 
Drupal8 for Symfony developers - Dutch PHP
Drupal8 for Symfony developers - Dutch PHPDrupal8 for Symfony developers - Dutch PHP
Drupal8 for Symfony developers - Dutch PHP
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

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
  • 13. Questions? @10up http://10up.com Eric A Mann @ericmann

Notas do Editor

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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
  6. 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.
  7. 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