{"id":10045,"date":"2024-08-28T19:59:08","date_gmt":"2024-08-28T14:59:08","guid":{"rendered":"https:\/\/arzhost.com\/blogs\/?p=10045"},"modified":"2024-09-10T17:06:23","modified_gmt":"2024-09-10T12:06:23","slug":"how-to-add-php-code-in-divi-builder-quick-guide","status":"publish","type":"post","link":"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/","title":{"rendered":"How to Add PHP Code in Divi Builder? Quick Guide"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#introduction_to_PHP_A_Powerful_Scripting_Language\" >introduction to PHP: A Powerful Scripting Language<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#First_what_is_Divi_Builder\" >First, what is Divi Builder?<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#Heres_a_breakdown_of_its_key_features\" >Here&#8217;s a breakdown of its key features:<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#Launch_Your_Own_Hosting_Business%E2%80%94Sign_Up_Now\" >Launch Your Own Hosting Business\u2014Sign Up Now!<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#Why_Add_PHP_Code_in_Divi_Builder\" >Why Add PHP Code in Divi Builder?<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#1_Enhanced_1_Enhanced_Functionality_with_PHP\" >1: Enhanced 1: Enhanced Functionality with PHP<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#2_Creating_Custom_Shortcodes_Using_PHP\" >2: Creating Custom Shortcodes Using PHP<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#3_Data_Integration_via_PHP\" >3: Data Integration via PHP<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#4_Improved_Performance_with_PHP_in_Divi\" >4: Improved Performance with PHP in Divi<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#5_Personalized_User_Experience_through_PHP\" >5: Personalized User Experience through PHP<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#4_Easy_Ways_to_Add_PHP_Code_in_WordPress_Divi_Builder\" >4 Easy Ways to Add PHP Code in WordPress Divi Builder<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#1_Convert_PHP_into_WordPress_Shortcodes\" >1: Convert PHP into WordPress Shortcodes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#2_Add_Sitewide_Code_Snippets_with_a_Plugin\" >2: Add Sitewide Code Snippets with a Plugin<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#3_Customize_Your_Child_Theme_in_WordPress\" >3: Customize Your Child Theme in WordPress<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#4_Use_an_FTP_Client_to_Edit_PHP_Files_Manually\" >4: Use an FTP Client to Edit PHP Files Manually<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#Boost_Your_Sites_Performance_with_VPS_Hosting_%E2%80%93_Best_Plans_Available\" >Boost Your Site\u2019s Performance with VPS Hosting &#8211; Best Plans Available<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#Can_I_Insert_PHP_Code_into_a_WordPress_Page_Without_a_Plugin\" >Can I Insert PHP Code into a WordPress Page Without a Plugin?<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#Editing_Theme_Files_Directly\" >Editing Theme Files Directly<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#Using_the_Code_Snippets_Plugin_as_a_Workaround\" >Using the Code Snippets Plugin as a Workaround<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#Conclusion\" >Conclusion&nbsp;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#FAQS_Frequently_Asked_Questions\" >FAQS (Frequently Asked Questions)<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#1_How_can_I_add_PHP_code_to_a_Divi_Builder_module_or_section\" >1: How can I add PHP code to a Divi Builder module or section?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#2_Is_it_safe_to_add_PHP_code_directly_into_the_Divi_Builder\" >2: Is it safe to add PHP code directly into the Divi Builder?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#3_Can_I_use_PHP_code_to_customize_specific_elements_in_Divi_modules\" >3: Can I use PHP code to customize specific elements in Divi modules?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#4_Are_there_any_limitations_or_considerations_when_using_PHP_in_Divi_Builder\" >4: Are there any limitations or considerations when using PHP in Divi Builder?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/arzhost.com\/blogs\/how-to-add-php-code-in-divi-builder-quick-guide\/#5_Can_I_use_PHP_to_create_custom_functions_or_extend_Divis_functionality\" >5: Can I use PHP to create custom functions or extend Divi&#8217;s functionality?<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"introduction_to_PHP_A_Powerful_Scripting_Language\"><\/span>introduction to PHP: A Powerful Scripting Language<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Divi Builder is one of the <strong>most popular WordPress page builders<\/strong>, known for its flexibility and ease of use. While it offers a wide range of pre-designed elements, there are times when you might want to add custom functionality to your website.&nbsp;<\/p>\n\n\n\n<p>This is where PHP comes in. <strong><a href=\"https:\/\/www.php.net\" data-type=\"link\" data-id=\"https:\/\/www.php.net\" target=\"_blank\" rel=\"noopener\">PHP<\/a><\/strong> is a powerful scripting language that can enhance your site&#8217;s capabilities beyond what Divi Builder offers out of the box.&nbsp;<\/p>\n\n\n\n<p>PHP is essential for WordPress customization and powers 78.8% of websites. With the help of this simple tutorial, you may improve the functionality of your WordPress website by adding or editing PHP in four simple methods.<\/p>\n\n\n\n<p>A&nbsp;basic awareness of PHP is necessary&nbsp;to add new code or majorly modify&nbsp;your WordPress website.<\/p>\n\n\n\n<p>PHP code can be easily integrated into WordPress without requiring direct file editing using plugins.<\/p>\n\n\n\n<p>For the highest level of flexibility and control, editing PHP files by hand via a child theme or FTP is recommended.<\/p>\n\n\n\n<p>In this guide, we&#8217;ll walk you through the steps to add PHP code in Divi Builder, ensuring you can customize your website to meet your specific needs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"First_what_is_Divi_Builder\"><\/span><strong>First, what is Divi Builder?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>WordPress developers,&nbsp;Elegant Themes created <a href=\"https:\/\/wordpress.org\/plugins\/tags\/divi-theme\/\" rel=\"nofollow noopener\" target=\"_blank\">Divi Builder<\/a>, a drag-and-drop page builder plugin. Without knowing any coding, anyone can build visually appealing websites. Divi Builder is ideal for both inexperienced and seasoned developers because of its abundance of modules and design options.<\/p>\n\n\n\n<p>Divi Builder is a popular website builder for WordPress that allows you to create and customize your website using a visual drag-and-drop interface. This means you don&#8217;t need to know any coding to build a website with Divi.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Heres_a_breakdown_of_its_key_features\"><\/span><strong>Here&#8217;s a breakdown of its key features:<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p><strong>Visual Drag-and-Drop Editing:<\/strong><\/p>\n\n\n\n<p>You can add, arrange, and edit elements on your webpage directly on the screen, seeing the changes as you make them.<\/p>\n\n\n\n<p><strong>Extensive Design Control:<\/strong><\/p>\n\n\n\n<p>Divi offers a high level of customization for fonts, colors, layouts, and more. You can design nearly every aspect of your website.<\/p>\n\n\n\n<p><strong>Theme Builder:<\/strong><\/p>\n\n\n\n<p>This feature lets you create custom templates for different parts of your website, like headers, footers, and blog posts.<\/p>\n\n\n\n<p><strong>Pre-Made Layouts<\/strong>:<\/p>\n\n\n\n<p>Divi comes with a library of pre-designed layouts that you can use as a starting point for your website.<\/p>\n\n\n\n<p>While Divi is beginner-friendly, it also offers advanced features for more experienced users. Overall, Divi Builder is a powerful tool that can help you create professional-looking websites without needing to code.<\/p>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-cf5921a7 wp-block-button uag-blocks-common-selector\" style=\"--z-index-desktop:479;;--z-index-tablet:undefined;;--z-index-mobile:undefined;\"><div class=\"uagb-cta__wrap\"><h2 class=\"uagb-cta__title\"><span class=\"ez-toc-section\" id=\"Launch_Your_Own_Hosting_Business%E2%80%94Sign_Up_Now\"><\/span><a href=\"https:\/\/arzhost.com\/reseller-hosting\/\" data-type=\"link\" data-id=\"https:\/\/arzhost.com\/reseller-hosting\/\">Launch Your Own Hosting Business\u2014Sign Up Now!<\/a><span class=\"ez-toc-section-end\"><\/span><\/h2><p class=\"uagb-cta__desc\">Start Reselling Hosting with Confidence &#8211; Economy Plan starts at <strong>$12.99\/-<\/strong><\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/arzhost.com\/reseller-hosting\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_self\" rel=\"noopener noreferrer\">Read More<\/a><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_Add_PHP_Code_in_Divi_Builder\"><\/span><strong>Why Add PHP Code in Divi Builder?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>One of the most well-known and flexible page builders for WordPress is Divi Builder, created by Elegant Themes. With its user-friendly drag-and-drop interface, users can easily construct beautiful websites.&nbsp;<\/p>\n\n\n\n<p>But occasionally, Divi Builder&#8217;s built-in capabilities might not be sufficient to fulfill particular requirements. Adding custom PHP code can be a useful remedy in certain situations.&nbsp;<\/p>\n\n\n\n<p>The following justifies why using PHP code in Divi Builder may be beneficial:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Enhanced_1_Enhanced_Functionality_with_PHP\"><\/span><strong>1: Enhanced 1: <strong>Enhanced Functionality with PHP<\/strong><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Divi Builder is robust, but it has its limitations. By adding custom PHP code, you can extend its functionality beyond the out-of-the-box features. Whether it&#8217;s creating dynamic content, integrating third-party APIs, or developing custom modules, PHP allows you to add functionalities that are not natively supported by Divi Builder.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<p>You might want to display the latest posts from a specific category or show a custom user profile section based on user roles. PHP can help you fetch and display this data dynamically.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;?php\n\n\/\/ Example of displaying the latest posts from a specific category\n\nfunction display_latest_posts_from_category($categorified) {\n\n\u00a0\u00a0\u00a0\u00a0$args = array (\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'cat' =&gt; $categorified,\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'Posts_per_page' =&gt; 5,\n\n\u00a0\u00a0\u00a0\u00a0);\n\n\u00a0\u00a0\u00a0\u00a0$query = new WP_Query($args);\n\n\u00a0\u00a0\u00a0\u00a0if ($query-&gt;have posts ()) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0while ($query-&gt;have posts ()) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$query-&gt;the_post ();\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0echo '&lt;h2&gt; \u2018. get_the_title (). '&lt;\/h2&gt;';\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0echo '&lt;p&gt; \u2018. get_the_excerpt (). '&lt;\/p&gt;';\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0wp_reset_postdata ();\n\n}\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">&lt;?<\/span><span style=\"color: #D8DEE9\">php<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">\/\/ Example of displaying the latest posts from a specific category<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">function<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">display_latest_posts_from_category<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">$categorified<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">$args<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">array<\/span><span style=\"color: #D8DEE9FF\"> (<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">cat<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=&gt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">$categorified<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">Posts_per_page<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=&gt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">5<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">$query<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">WP_Query<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #D8DEE9\">$args<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> (<\/span><span style=\"color: #D8DEE9\">$query<\/span><span style=\"color: #81A1C1\">-&gt;<\/span><span style=\"color: #D8DEE9\">have<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">posts<\/span><span style=\"color: #D8DEE9FF\"> ()) <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #81A1C1\">while<\/span><span style=\"color: #D8DEE9FF\"> (<\/span><span style=\"color: #D8DEE9\">$query<\/span><span style=\"color: #81A1C1\">-&gt;<\/span><span style=\"color: #D8DEE9\">have<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">posts<\/span><span style=\"color: #D8DEE9FF\"> ()) <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">$query<\/span><span style=\"color: #81A1C1\">-&gt;<\/span><span style=\"color: #88C0D0\">the_post<\/span><span style=\"color: #D8DEE9FF\"> ()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">echo<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">&lt;h2&gt; \u2018. get_the_title (). <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #81A1C1\">&lt;\/<\/span><span style=\"color: #D8DEE9\">h2<\/span><span style=\"color: #81A1C1\">&gt;<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">echo<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">&lt;p&gt; \u2018. get_the_excerpt (). <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #81A1C1\">&lt;\/<\/span><span style=\"color: #D8DEE9\">p<\/span><span style=\"color: #81A1C1\">&gt;<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #88C0D0\">wp_reset_postdata<\/span><span style=\"color: #D8DEE9FF\"> ()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Creating_Custom_Shortcodes_Using_PHP\"><\/span><strong>2: <strong>Creating Custom Shortcodes Using PHP<\/strong><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p><strong>Shortcodes are a great way to add custom content<\/strong> to your WordPress site without writing HTML each time. With PHP, you can create custom shortcodes that can be easily inserted into Divi Builder modules, enhancing your site\u2019s interactivity and functionality.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<p>Creating a custom shortcode for displaying the current year:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;?php\n\nfunction display_current_year () {\n\n\u00a0\u00a0\u00a0\u00a0return date('Y');\n\n}\n\nadd_shortcode ('current year', 'display_current_year');\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">&lt;?<\/span><span style=\"color: #D8DEE9\">php<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">function<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">display_current_year<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">date<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">Y<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #88C0D0\">add_shortcode<\/span><span style=\"color: #D8DEE9FF\"> (<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">current year<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">display_current_year<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\">);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Now, you can use [current year] in any Divi text module, and it will dynamically display the current year.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Data_Integration_via_PHP\"><\/span><strong>3: <strong>Data Integration via PHP<\/strong><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Integrating external data sources or APIs can greatly enrich your website. PHP makes it possible to connect to various APIs, fetch data, and display it within your Divi-designed pages.&nbsp;<\/p>\n\n\n\n<p>This is particularly useful for websites that require real-time data, such as weather updates, stock prices, or social media feeds.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<p>Fetching and displaying weather information from an external API:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;?php\n\nfunction fetch_weather_data ($city) {\n\n\u00a0\u00a0\u00a0\u00a0$api_url = &quot;http:\/\/api.weatherapi.com\/v1\/current.json?key=YOUR_API_KEY&amp;q= \u201c. $city;\n\n\u00a0\u00a0\u00a0\u00a0$response = wp_remote_get ($api_url);\n\n\u00a0\u00a0\u00a0\u00a0if (is_array($response) &amp;! is_wp_error($response)) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$body = wp_remote_retrieve_body ($response);\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$data = Json decode ($body);\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (isset($data-&gt;current)) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0echo '&lt;p&gt;Temperature: \u2018. $data-&gt;current-&gt;temp_c. '\u00b0C&lt;\/p&gt;';\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0echo '&lt;p&gt;Condition: \u2018. $data-&gt;current-&gt;condition-&gt;text. '&lt;\/p&gt;';\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0}\n\n}\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">&lt;?<\/span><span style=\"color: #D8DEE9\">php<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">function<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">fetch_weather_data<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">$city<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">$api_url<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">http:\/\/api.weatherapi.com\/v1\/current.json?key=YOUR_API_KEY&amp;q= \u201c. $city<\/span><span style=\"color: #D8DEE9\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">$response<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">wp_remote_get<\/span><span style=\"color: #D8DEE9FF\"> (<\/span><span style=\"color: #D8DEE9\">$api_url<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> (<\/span><span style=\"color: #88C0D0\">is_array<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #D8DEE9\">$response<\/span><span style=\"color: #D8DEE9FF\">) <\/span><span style=\"color: #81A1C1\">&amp;!<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">is_wp_error<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #D8DEE9\">$response<\/span><span style=\"color: #D8DEE9FF\">)) <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">$body<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">wp_remote_retrieve_body<\/span><span style=\"color: #D8DEE9FF\"> (<\/span><span style=\"color: #D8DEE9\">$response<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">$data<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">Json<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">decode<\/span><span style=\"color: #D8DEE9FF\"> (<\/span><span style=\"color: #D8DEE9\">$body<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> (<\/span><span style=\"color: #88C0D0\">isset<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #D8DEE9\">$data<\/span><span style=\"color: #81A1C1\">-&gt;<\/span><span style=\"color: #D8DEE9\">current<\/span><span style=\"color: #D8DEE9FF\">)) <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">echo<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">&lt;p&gt;Temperature: \u2018. $data-&gt;current-&gt;temp_c. <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\">\u00b0<\/span><span style=\"color: #D8DEE9\">C<\/span><span style=\"color: #81A1C1\">&lt;\/<\/span><span style=\"color: #D8DEE9\">p<\/span><span style=\"color: #81A1C1\">&gt;<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">echo<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">&lt;p&gt;Condition: \u2018. $data-&gt;current-&gt;condition-&gt;text. <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #81A1C1\">&lt;\/<\/span><span style=\"color: #D8DEE9\">p<\/span><span style=\"color: #81A1C1\">&gt;<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Improved_Performance_with_PHP_in_Divi\"><\/span><strong>4: <strong>Improved Performance with PHP in Divi<\/strong><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Sometimes, relying solely on Divi Builder\u2019s visual modules can lead to performance issues, especially with complex layouts and large amounts of data. Custom PHP code can help streamline processes, reduce server load, and improve the overall performance of your website.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<p>Using PHP to cache and display data can significantly reduce load times.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;?php\n\nfunction display_cached_data () {\n\n\u00a0\u00a0\u00a0\u00a0$cached_data = get transient ('my_custom_cache');\n\n\u00a0\u00a0\u00a0\u00a0if (! $cached_data) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Simulating data fetching process\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$cached_data = 'Some fetched data';\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0set transient ('my_custom_cache', $cached_data, 12 * HOUR_IN_SECONDS);\n\n\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0echo $cached_data;\n\n}\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">&lt;?<\/span><span style=\"color: #D8DEE9\">php<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">function<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">display_cached_data<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">$cached_data<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">get<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">transient<\/span><span style=\"color: #D8DEE9FF\"> (<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">my_custom_cache<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> (<\/span><span style=\"color: #81A1C1\">!<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">$cached_data<\/span><span style=\"color: #D8DEE9FF\">) <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #616E88\">\/\/ Simulating data fetching process<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">$cached_data<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">Some fetched data<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">set<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">transient<\/span><span style=\"color: #D8DEE9FF\"> (<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">my_custom_cache<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">$cached_data<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">12<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">HOUR_IN_SECONDS<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">echo<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">$cached_data<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Personalized_User_Experience_through_PHP\"><\/span><strong>5: <strong>Personalized User Experience through PHP<\/strong><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>With PHP, you can create personalized experiences for your visitors. By leveraging WordPress\u2019s user functions, you can display personalized content based on user roles, logged-in status, or custom user metadata.&nbsp;<\/p>\n\n\n\n<p>This level of customization can significantly enhance user engagement and satisfaction.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<p>Displaying a custom greeting based on user roles:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;?php\n\nfunction display_custom_greeting () {\n\n\u00a0\u00a0\u00a0\u00a0if (is_user_logged_in ()) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$current_user = wp_get_current_user ();\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (in array ('administrator', $current_user-&gt;roles)) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0echo '&lt;p&gt;Welcome, Admin! &lt;\/p&gt;';\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} else {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0echo '&lt;p&gt;Welcome, \u2018. $current_user-&gt;display_name. \u2018! &lt;\/p&gt;';\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0} else {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0echo '&lt;p&gt;Welcome, Guest!&lt;\/p&gt;';\n\n\u00a0\u00a0\u00a0\u00a0}\n\n}\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">&lt;?<\/span><span style=\"color: #D8DEE9\">php<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">function<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">display_custom_greeting<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> (<\/span><span style=\"color: #88C0D0\">is_user_logged_in<\/span><span style=\"color: #D8DEE9FF\"> ()) <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">$current_user<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">wp_get_current_user<\/span><span style=\"color: #D8DEE9FF\"> ()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> (<\/span><span style=\"color: #81A1C1\">in<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">array<\/span><span style=\"color: #D8DEE9FF\"> (<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">administrator<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">$current_user<\/span><span style=\"color: #81A1C1\">-&gt;<\/span><span style=\"color: #D8DEE9\">roles<\/span><span style=\"color: #D8DEE9FF\">)) <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">echo<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">&lt;p&gt;Welcome, Admin! &lt;\/p&gt;<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #ECEFF4\">}<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">else<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">echo<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">&lt;p&gt;Welcome, \u2018. $current_user-&gt;display_name. \u2018! &lt;\/p&gt;<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #ECEFF4\">}<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">else<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #D8DEE9\">echo<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">&lt;p&gt;Welcome, Guest!&lt;\/p&gt;<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Adding PHP code in Divi Builder is a powerful way to enhance your website\u2019s functionality, performance, and user experience.&nbsp;<\/p>\n\n\n\n<p>While Divi Builder offers an excellent array of tools for designing beautiful websites, the ability to incorporate custom PHP code opens up endless possibilities for developers and advanced users.&nbsp;<\/p>\n\n\n\n<p>Whether you need to integrate external data, create custom shortcodes, or personalize content, PHP provides the flexibility and power to take your Divi-built site to the next level.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Easy_Ways_to_Add_PHP_Code_in_WordPress_Divi_Builder\"><\/span><strong>4 Easy Ways to Add PHP Code in WordPress Divi Builder<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2024\/08\/We-Have-A-Custom-plan-1.jpg\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"536\" title=\"4 Ways to Add PHP to Divi Builder\" src=\"https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2024\/08\/We-Have-A-Custom-plan-1-1024x536.jpg\" alt=\"4 Ways to Add PHP to Divi Builder\" class=\"wp-image-10058\" srcset=\"https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2024\/08\/We-Have-A-Custom-plan-1-1024x536.jpg 1024w, https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2024\/08\/We-Have-A-Custom-plan-1-300x157.jpg 300w, https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2024\/08\/We-Have-A-Custom-plan-1-768x402.jpg 768w, https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2024\/08\/We-Have-A-Custom-plan-1-150x79.jpg 150w, https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2024\/08\/We-Have-A-Custom-plan-1-450x236.jpg 450w, https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2024\/08\/We-Have-A-Custom-plan-1.jpg 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">4 Ways to Add PHP to Divi Builder<\/figcaption><\/figure>\n\n\n\n<p>The Divi Builder by Elegant Themes is a powerful and popular WordPress page builder that allows users to create stunning websites with ease. However, sometimes you might need to add custom PHP code to your Divi-built pages to achieve specific functionalities that aren&#8217;t available by default.&nbsp;<\/p>\n\n\n\n<p>Here are four easy methods to incorporate PHP code into your Divi Builder pages:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Convert PHP into WordPress Shortcodes<\/li>\n\n\n\n<li>Add Sitewide Code Snippets with a Plugin<\/li>\n\n\n\n<li>Customize Your Child Theme in WordPress<\/li>\n\n\n\n<li>Use an FTP Client to Edit PHP Files Manually<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Convert_PHP_into_WordPress_Shortcodes\"><\/span><strong>1: Convert PHP into WordPress Shortcodes<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>As usual, the easiest way to solve a particular WordPress issue is through plugins. To <strong>add custom code to your WordPress files<\/strong> without having to change them directly, you can utilize several plugins. You will need to learn the <strong><a href=\"https:\/\/arzhost.com\/blogs\/what-are-wordpress-coding-standards\/\" data-type=\"link\" data-id=\"https:\/\/arzhost.com\/blogs\/what-are-wordpress-coding-standards\/\">WordPress Coding Standards<\/a><\/strong> to easily understand and create a custom Function.<\/p>\n\n\n\n<p>Creating shortcodes out of your PHP code snippets so you can quickly utilize them in widget areas or the WordPress editor is one way. If you want to add PHP to a certain post or page on your website, this is helpful.<\/p>\n\n\n\n<p>WordPress shortcodes are an excellent way to add dynamic content to your posts and pages without writing complex code. By converting your PHP code into a shortcode, you can easily insert it into any part of your Divi layout.<\/p>\n\n\n\n<p>Steps:<\/p>\n\n\n\n<p><strong>1: Create a Custom Function:<\/strong><\/p>\n\n\n\n<p>Open your theme&#8217;s functions.php file (preferably in a child theme to prevent changes from being overwritten during updates) and create a custom function that contains your PHP code.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"function my_custom_shortcode () {\n\n\u00a0\u00a0\u00a0\u00a0\/\/ Your PHP code here\n\n\u00a0\u00a0\u00a0\u00a0return 'Output from your PHP code';\n\n}\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">function<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">my_custom_shortcode<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #616E88\">\/\/ Your PHP code here<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">Output from your PHP code<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>2: Register the Shortcode:<\/strong><\/p>\n\n\n\n<p>Add the following line to register your custom function as a shortcode.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"add_shortcode ('my_shortcode', 'my_custom_shortcode');\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #88C0D0\">add_shortcode<\/span><span style=\"color: #D8DEE9FF\"> (<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">my_shortcode<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">my_custom_shortcode<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>3: Use the Shortcode in Divi:<\/strong><\/p>\n\n\n\n<p>In the Divi Builder, use the Text Module to add the shortcode [my_shortcode] wherever you want the PHP code to execute.<\/p>\n\n\n\n<p>This method is straightforward and keeps your PHP code organized within WordPress shortcodes.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Add_Sitewide_Code_Snippets_with_a_Plugin\"><\/span><strong>2: Add Sitewide Code Snippets with a Plugin<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>If you want to add PHP code that runs across your entire site, using a plugin designed for managing code snippets is a good option. Plugins like <strong>&#8220;Code Snippets&#8221;<\/strong> or <strong>&#8220;Insert PHP Code Snippet&#8221;<\/strong> are excellent choices.<\/p>\n\n\n\n<p>Steps:<\/p>\n\n\n\n<p><strong>1: Install and Activate the Plugin:<\/strong><\/p>\n\n\n\n<p>Go to the WordPress admin dashboard, navigate to Plugins &gt; Add New, search for &#8220;Code Snippets,&#8221; and install and activate the plugin.<\/p>\n\n\n\n<p><strong>2: Add a New Snippet:<\/strong><\/p>\n\n\n\n<p>Go to the new &#8220;Snippets&#8221; menu in your dashboard and click &#8220;Add New.&#8221; Give your snippet a name and paste your PHP code into the code field.<\/p>\n\n\n\n<p><strong>3: Choose Where to Execute:<\/strong><\/p>\n\n\n\n<p>Depending on the plugin, you can specify where your code should run (e.g., in the header, footer, or specific posts\/pages).<\/p>\n\n\n\n<p><strong>4: Use the Snippet in Divi:<\/strong><\/p>\n\n\n\n<p>If the plugin provides a shortcode for your snippet, you can insert it directly into the Divi Builder using a Text Module.<\/p>\n\n\n\n<p>This approach is useful for managing multiple snippets and keeping your PHP code separate from your theme files.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Customize_Your_Child_Theme_in_WordPress\"><\/span><strong>3: Customize Your Child Theme in WordPress<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>You can edit your theme files right from the dashboard of WordPress using a tool called Theme Editor. Ideally, you should be doing this using a child theme so that when you update the primary theme, any changes you make are preserved.<\/p>\n\n\n\n<p>Creating a child theme is a best practice for customizing WordPress themes without losing your changes when the parent theme updates. You can add your PHP code directly to the child theme&#8217;s files.<\/p>\n\n\n\n<p>Steps:<\/p>\n\n\n\n<p><strong>1: Create a Child Theme:<\/strong><\/p>\n\n\n\n<p>If you don\u2019t already have a child theme, create one by creating a new folder in your wp-content\/themes\/ directory. Inside this folder, create a style.css file and add the following header:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/*\n\nTheme Name: \u00a0 Your Child Theme\n\nTemplate: \u00a0 \u00a0 parent-theme-folder-name\n\n*\/\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #616E88\">\/*<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">Theme Name: \u00a0 Your Child Theme<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">Template: \u00a0 \u00a0 parent-theme-folder-name<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">*\/<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Also, create a functions.php file where you will add your PHP code.<\/p>\n\n\n\n<p><strong>2: Add PHP Code to functions.php:<\/strong><\/p>\n\n\n\n<p>Open the functions.php file in your child theme and add your custom PHP functions.<\/p>\n\n\n\n<p>function my_custom_function () {<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\/\/ Your PHP code here<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p><strong>3: Integrate with Divi:<\/strong><\/p>\n\n\n\n<p>If needed, you can create shortcodes or directly call your custom functions within Divi modules using the do_shortcode function.<\/p>\n\n\n\n<p>Using a child theme ensures that your customizations are preserved and allows for more extensive modifications to your site\u2019s functionality.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Use_an_FTP_Client_to_Edit_PHP_Files_Manually\"><\/span><strong>4: Use an FTP Client to Edit PHP Files Manually<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Its basic functionality is the primary drawback of utilizing the WordPress Theme Editor. Modifying files from your dashboard is a great way to lose out on a lot of capability if you&#8217;ve ever used a full code editor.<\/p>\n\n\n\n<p>Using your preferred text editor to make updates, you can retrieve the files from your website over File Transfer Protocol (FTP). You&#8217;ll need an FTP client, like FileZilla, to accomplish this.<\/p>\n\n\n\n<p>You will need to find the login information for your website if this is your first time using an FTP client. The credentials you use to get into WordPress are different from your FTP credentials.<\/p>\n\n\n\n<p>For more advanced users comfortable with editing code directly, using an FTP client to access and modify your site\u2019s files can be the most direct method.<\/p>\n\n\n\n<p>Steps:<\/p>\n\n\n\n<p><strong>1: Connect to Your Server via FTP:<\/strong><\/p>\n\n\n\n<p>Use an FTP client like FileZilla to connect to your web server. You will need your FTP credentials, which are usually provided by your hosting provider.<\/p>\n\n\n\n<p><strong>2: Navigate to Your Theme\u2019s Directory:<\/strong><\/p>\n\n\n\n<p>Once connected, navigate to the wp-content\/themes\/your-theme directory. It\u2019s advisable to work within a child theme to prevent your changes from being overwritten. If the <strong><a href=\"https:\/\/arzhost.com\/blogs\/ftp-directory-listing-not-working\/\" data-type=\"link\" data-id=\"https:\/\/arzhost.com\/blogs\/ftp-directory-listing-not-working\/\">FTP Directory is not working click here to fix it<\/a><\/strong>.<\/p>\n\n\n\n<p><strong>3: Edit PHP Files:<\/strong><\/p>\n\n\n\n<p>Open the functions.php file or create a new PHP file if you prefer to keep your functions separate. Add your custom PHP code.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"function my_custom_code () {\n\n\u00a0\u00a0\u00a0\u00a0\/\/ Your PHP code here\n\n}\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">function<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">my_custom_code<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #616E88\">\/\/ Your PHP code here<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>4: Apply Changes in Divi:<\/strong><\/p>\n\n\n\n<p>If your PHP code is in the form of a shortcode or function, you can use it within the Divi Builder as explained in the previous methods.<\/p>\n\n\n\n<p>Editing files via FTP provides complete control over your site\u2019s code and is ideal for advanced customizations.<\/p>\n\n\n\n<p>Adding PHP code to your WordPress site using the Divi Builder can be done in several ways, each with its advantages. Whether you prefer using shortcodes, managing snippets via plugins, customizing a child theme, or editing files directly via FTP, you have multiple options to suit your level of expertise and specific needs.&nbsp;<\/p>\n\n\n\n<p>Always remember to back up your site before making any changes to your code to avoid any potential issues.<\/p>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-1e518341 wp-block-button uag-blocks-common-selector\" style=\"--z-index-desktop:479;;--z-index-tablet:undefined;;--z-index-mobile:undefined;\"><div class=\"uagb-cta__wrap\"><h2 class=\"uagb-cta__title\"><span class=\"ez-toc-section\" id=\"Boost_Your_Sites_Performance_with_VPS_Hosting_%E2%80%93_Best_Plans_Available\"><\/span><a href=\"https:\/\/arzhost.com\/vps\/\" data-type=\"link\" data-id=\"https:\/\/arzhost.com\/vps\/\">Boost Your Site\u2019s Performance with VPS Hosting &#8211; Best Plans Available<\/a><span class=\"ez-toc-section-end\"><\/span><\/h2><p class=\"uagb-cta__desc\">Unlock the Potential of VPS Hosting &#8211; Starter Plan starts at just <strong>$12.50\/month<\/strong><\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/arzhost.com\/vps\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_self\" rel=\"noopener noreferrer\">Read More<\/a><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Can_I_Insert_PHP_Code_into_a_WordPress_Page_Without_a_Plugin\"><\/span><strong>Can I Insert PHP Code into a WordPress Page Without a Plugin?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Yes, you can insert PHP code into a WordPress page without a plugin, but it&#8217;s important to proceed with caution.&nbsp; Using plugins is generally the safer and more recommended approach for beginners.&nbsp;&nbsp;<\/p>\n\n\n\n<p>However, if you&#8217;re comfortable with code, there are two main ways to achieve this:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Editing_Theme_Files_Directly\"><\/span><strong><strong>Editing Theme Files Directly<\/strong><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>This method involves editing your theme&#8217;s files directly. You can access the theme files through your WordPress dashboard or using an FTP client. It&#8217;s recommended to create a child theme before making any edits to avoid losing changes during theme updates.&nbsp;<\/p>\n\n\n\n<p>You can then insert your PHP code into specific theme files depending on where you want it to appear (e.g., header, footer, specific page template).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_the_Code_Snippets_Plugin_as_a_Workaround\"><\/span><strong><strong>Using the Code Snippets Plugin as a Workaround<\/strong><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>While this might seem contradictory, you can use a lightweight plugin like &#8220;Code Snippets&#8221; to add your code. This offers a more user-friendly way to insert code compared to directly editing theme files. However, it&#8217;s still important to understand the code you&#8217;re adding and avoid bloating your site with unnecessary plugins.<\/p>\n\n\n\n<p>Remember, improperly coded PHP can break your website.&nbsp; Always back up your website before making any code changes.&nbsp; If you&#8217;re unsure, using a plugin or consulting a developer is recommended.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><strong>Conclusion&nbsp;<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>With WordPress, you can customize and increase the functionality of your website with great ease thanks to the widely-used PHP scripting language. Gaining an understanding of PHP&#8217;s function and how WordPress operates will enable you to make the most of your website.<\/p>\n\n\n\n<p>WordPress makes it fairly easy to edit and add PHP. Should you possess the ability to deal with code, or even just copy and paste it, you can incorporate snippets that will dramatically improve the functioning of your website.<\/p>\n\n\n\n<p>But you should always make a backup of your website before adding any code to WordPress, just in case. For example, introducing PHP with incorrect syntax could cause WordPress to enter recovery mode.<\/p>\n\n\n\n<p>We hope that this post helped you in using WordPress&#8217; PHP code to customize your website. If you still have questions, feel free to ask them in the space provided for comments below or in our FAQ section.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"FAQS_Frequently_Asked_Questions\"><\/span><strong>FAQS (Frequently Asked Questions)<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_How_can_I_add_PHP_code_to_a_Divi_Builder_module_or_section\"><\/span><strong>1: How can I add PHP code to a Divi Builder module or section?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Adding PHP code to Divi Builder modules or sections involves a few steps. First, you need to access the page where you want to insert the PHP code using the Divi Builder. Navigate to the backend of your WordPress site and edit the page with Divi Builder. Once you&#8217;re in the Visual Builder or Backend Editor, add a new module or edit an existing one.<\/p>\n\n\n\n<p>To include PHP code, you typically use the Code module provided by Divi. This module allows you to insert HTML, CSS, JavaScript, and PHP code directly into your page.&nbsp;<\/p>\n\n\n\n<p>Simply add the Code module to your section or row, open its settings, and paste your PHP code in the provided text area. Ensure your PHP code is correctly formatted and follows best practices to avoid syntax errors.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Is_it_safe_to_add_PHP_code_directly_into_the_Divi_Builder\"><\/span><strong>2: Is it safe to add PHP code directly into the Divi Builder?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Yes, it is generally safe to add PHP code into the Divi Builder, provided you understand what the code does and where it comes from. PHP code inserted via the Code module in Divi is executed server-side, meaning it doesn&#8217;t pose direct security risks like client-side scripting languages (e.g., JavaScript). However, improper PHP code can still cause functionality issues or errors on your site.<\/p>\n\n\n\n<p>To ensure safety, always use PHP code from trusted sources or code that you have thoroughly reviewed. Avoid copying and pasting PHP code from untrusted websites or forums, as it could contain malicious or flawed code that might compromise your site&#8217;s security or stability.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Can_I_use_PHP_code_to_customize_specific_elements_in_Divi_modules\"><\/span><strong>3: Can I use PHP code to customize specific elements in Divi modules?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Yes, PHP code can be used to customize specific elements within Divi modules. For example, you might want to dynamically display content based on certain conditions, retrieve data from external sources, or manipulate the output of a module based on user interactions or backend calculations.<\/p>\n\n\n\n<p>To achieve this, identify the module or section where you want to apply customization. Use the Code module to insert PHP snippets that interact with WordPress functions, Divi&#8217;s API, or other plugins integrated into your site.&nbsp;<\/p>\n\n\n\n<p>This allows for extensive customization beyond what Divi&#8217;s visual interface offers, making your website more dynamic and tailored to your specific needs.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Are_there_any_limitations_or_considerations_when_using_PHP_in_Divi_Builder\"><\/span><strong>4: Are there any limitations or considerations when using PHP in Divi Builder?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>While PHP offers powerful customization capabilities, there are several considerations and limitations to keep in mind when using it within Divi Builder:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Compatibility:<\/strong> Ensure PHP code is compatible with the version of PHP running on your web server and with other plugins or themes on your site. See <strong><a href=\"https:\/\/arzhost.com\/blogs\/how-to-check-your-php-version\/\" data-type=\"link\" data-id=\"https:\/\/arzhost.com\/blogs\/how-to-check-your-php-version\/\"> How to Check your PHP version<\/a><\/strong>.<\/li>\n\n\n\n<li><strong>Performance:<\/strong> Poorly optimized PHP code can impact site performance. Minimize database queries and resource-intensive operations. <\/li>\n\n\n\n<li><strong>Maintenance:<\/strong> Regularly review and update PHP code to ensure compatibility with <a href=\"https:\/\/arzhost.com\/blogs\/upcoming-wordpress-6-5\/\" data-type=\"link\" data-id=\"https:\/\/arzhost.com\/blogs\/upcoming-wordpress-6-5\/\"><strong>updates to WordPress<\/strong><\/a>, Divi, and other plugins.<\/li>\n<\/ul>\n\n\n\n<p>Additionally, Divi&#8217;s Code module imposes some restrictions on PHP usage to prevent potential security risks and maintain stability. Always test PHP code thoroughly in a staging environment before deploying it to a live site to avoid unintended consequences.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Can_I_use_PHP_to_create_custom_functions_or_extend_Divis_functionality\"><\/span><strong>5: Can I use PHP to create custom functions or extend Divi&#8217;s functionality?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Yes, PHP can be used to create custom functions and extend the functionality of Divi beyond its built-in features. This is particularly useful for advanced users or developers looking to integrate custom features, automate processes, or enhance user interactions.<\/p>\n\n\n\n<p>To create custom functions using PHP in Divi, you can leverage WordPress hooks, actions, and filters. Define your custom PHP functions in your theme&#8217;s functions.php file or within a custom plugin. These functions can modify Divi&#8217;s behavior, interact with external APIs, or perform complex calculations based on your specific requirements.<\/p>\n\n\n\n<p>Using PHP in this manner allows you to tailor Divi to meet unique project needs, making your website more versatile and capable of handling diverse functionalities seamlessly.<\/p>\n\n\n\n<p><strong>Read More:<\/strong><\/p>\n\n\n<ul class=\"wp-block-latest-posts__list wp-block-latest-posts\"><li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/how-to-fix-403-forbidden-error-wordpress\/\">How To Fix 403 Forbidden Error WordPress<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/how-to-get-the-most-out-of-claude-ai\/\">How To Get The Most Out Of Claude Ai<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/bad-gateway-error-502-the-ultimate-guide-to-quick-fixes\/\">Bad Gateway Error (502): The Ultimate Guide to Quick Fixes<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/a-deep-dive-into-todays-best-linux-distros\/\">A Deep Dive Into Today\u2019s Best Linux Distros<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/domain-investor-terms-powerful-strategy\/\">Domain Investor Terms: Expert Insight on Powerful Strategy<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>introduction to PHP: A Powerful Scripting Language Divi Builder is one of the most popular WordPress page builders, known for its flexibility and ease of use. While it offers a wide range of pre-designed elements, there are times when you might want to add custom functionality to your website.&nbsp; This is where PHP comes in. [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":10057,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[117],"tags":[],"table_tags":[],"class_list":["post-10045","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts\/10045","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/comments?post=10045"}],"version-history":[{"count":0,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts\/10045\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/media\/10057"}],"wp:attachment":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/media?parent=10045"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/categories?post=10045"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/tags?post=10045"},{"taxonomy":"table_tags","embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/table_tags?post=10045"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}