Sigma 1 Logo
_OXY_OPENING_BRACKET_oxy-mega-menu ct_sign_sha256='1a09ff2b294aea92ec2403432c89e4a731b087902cc0c0cc5d5d2bcb5388e14f' ct_options='{"original":{"oxy-mega-menu_type":"individual","oxy-mega-menu_maybe_mouseover":"true","oxy-mega-menu_container_width":"a_none","oxy-mega-menu_slug_oxymegadropdowninner___global_dropdown_width":"360","oxy-mega-menu_slug_oxymegadropdowncontaineroxymegadropdownflyoutsubmenu_background_color":"#f7f7f7","oxy-mega-menu_-oxy-mega-dropdown-container- -oxy-mega-dropdown-flyout -sub-menu_box_shadow_box-shadow-color":"rgba(0,0,0,0.13)","oxy-mega-menu_-oxy-mega-dropdown-container- -oxy-mega-dropdown-flyout -sub-menu_box_shadow_box-shadow-horizontal-offset":"0","oxy-mega-menu_-oxy-mega-dropdown-container- -oxy-mega-dropdown-flyout -sub-menu_box_shadow_box-shadow-vertical-offset":"0","oxy-mega-menu_-oxy-mega-dropdown-container- -oxy-mega-dropdown-flyout -sub-menu_box_shadow_box-shadow-blur":"10","oxy-mega-menu_content_animation_reveal":"transform","oxy-mega-menu_slug_oxymegadropdowninneropenoxymegadropdowncontent_transition_duration":"600","oxy-mega-menu_slug_oxymegadropdowncontent___dropdown_content_translatex":"10","oxy-mega-menu_slug_oxymegadropdowncontent___dropdown_content_scale":"1","oxy-mega-menu_slug_oxymegadropdowncontent_transition_duration":"400","oxy-mega-menu_mobile_menu_below":"tablet","font-family":{"0":"global","1":"Display"},"oxy-mega-menu_force_column_collapse":"false"},"media":{"phone-landscape":{"original":{"oxy-mega-menu_slug____megamenu_responsive_background":"color(18)","oxy-mega-menu_slug_oxymegadropdownlinkoxymegamenuinnerctlinktext_padding_left":"20","oxy-mega-menu_slug_oxymegadropdownlinkoxymegamenuinnerctlinktext_padding_right":"20","oxy-mega-menu_slug_oxymegadropdownlinkoxymegamenuinnerctlinktext_padding_top":"20","oxy-mega-menu_slug_oxymegadropdownlinkoxymegamenuinnerctlinktext_padding_bottom":"20","box-shadow-color":"rgba(0,0,0,0.05)","box-shadow-horizontal-offset":"0","box-shadow-vertical-offset":"23","box-shadow-blur":"50"}},"tablet":{"original":{"oxy-mega-menu_slug____megamenu_responsive_background":"color(3)","oxy-mega-menu_slug_oxymegadropdownlinkoxymegamenuinnerctlinktext_padding_left":"20","oxy-mega-menu_slug_oxymegadropdownlinkoxymegamenuinnerctlinktext_padding_right":"20","oxy-mega-menu_slug_oxymegadropdownlinkoxymegamenuinnerctlinktext_padding_top":"20","oxy-mega-menu_slug_oxymegadropdownlinkoxymegamenuinnerctlinktext_padding_bottom":"20"}}},"classes":{},"ct_id":375,"ct_parent":374,"selector":"-mega-menu-375-13","activeselector":false}'_OXY_CLOSING_BRACKET__OXY_OPENING_BRACKET_oxy-mega-dropdown ct_sign_sha256='dd0e1ed7d7bfe73869a3599bcd3b766735d4d2b20a2ce2d313c3cbf7d0295515' ct_options='{"ct_id":376,"ct_parent":375,"selector":"-mega-dropdown-376-13","original":{"oxy-mega-dropdown_dropdown_elements":"none","oxy-mega-dropdown_link_text":"oxy_base64_encoded::SG9tZQ==","oxy-mega-dropdown_hashlink":"oxy_base64_encoded::Lw=="},"classes":{"0":"mega-header-item"}}'_OXY_CLOSING_BRACKET__OXY_OPENING_BRACKET_/oxy-mega-dropdown_OXY_CLOSING_BRACKET__OXY_OPENING_BRACKET_oxy-mega-dropdown ct_sign_sha256='0c2d09f73246efb38d783c6780f4841958a36de84967af495e849e0a7e268369' ct_options='{"ct_id":377,"ct_parent":375,"selector":"-mega-dropdown-377-13","original":{"oxy-mega-dropdown_dropdown_elements":"none","oxy-mega-dropdown_dropdown_align":"b_center","oxy-mega-dropdown_dropdown_padding_padding-top":"20","oxy-mega-dropdown_dropdown_padding_padding-left":"20","oxy-mega-dropdown_dropdown_padding_padding-right":"20","oxy-mega-dropdown_dropdown_padding_padding-bottom":"20","padding-left":"0","padding-right":"0","padding-bottom":"0","padding-top":"0","oxy-mega-dropdown_link_text":"oxy_base64_encoded::V2ViIERlc2lnbg==","oxy-mega-dropdown_dropdown_width":"b_none","oxy-mega-dropdown_slug_oxymegadropdowninner___custom_dropdown_width":"360","oxy-mega-dropdown_dropdown_relative_positioning":"link","oxy-mega-dropdown_-oxy-mega-dropdown-content_flex_flex-direction":"column","aos-enable":"false","aos-type":"flip-down","oxy-mega-dropdown_hashlink":"oxy_base64_encoded::L3dlYi1kZXNpZ24tYW5kLWRldmVsb3BtZW50LXNlcnZpY2VzLWluLWxhcy12ZWdhcw==","oxy-mega-dropdown_slug_oxymegadropdownicon_font_size":"0"},"media":{"phone-landscape":{"original":{"oxy-mega-dropdown_slug_oxymegadropdowniconsvg_transform:rotate":"270","oxy-mega-dropdown_slug_oxymegadropdownlinkoxymegadropdowninneropenoxymegadropdowniconsvg_transform:rotate":"0","oxy-mega-dropdown_slug_oxymegadropdowniconsvg_transition_duration":"400"}}},"classes":{"0":"mega-header-item"}}'_OXY_CLOSING_BRACKET__OXY_OPENING_BRACKET_/oxy-mega-dropdown_OXY_CLOSING_BRACKET__OXY_OPENING_BRACKET_oxy-mega-dropdown ct_sign_sha256='40ec6527c11c7395d394ba3da1bcbc78064ac8bb40be8b4bb18987c3581a2e85' ct_options='{"ct_id":396,"ct_parent":375,"selector":"-mega-dropdown-396-13","original":{"oxy-mega-dropdown_dropdown_elements":"none","oxy-mega-dropdown_dropdown_align":"b_center","oxy-mega-dropdown_dropdown_padding_padding-top":"20","oxy-mega-dropdown_dropdown_padding_padding-left":"20","oxy-mega-dropdown_dropdown_padding_padding-right":"20","oxy-mega-dropdown_dropdown_padding_padding-bottom":"20","padding-left":"0","padding-right":"0","padding-bottom":"0","padding-top":"0","oxy-mega-dropdown_link_text":"oxy_base64_encoded::TWFya2V0aW5n","oxy-mega-dropdown_dropdown_width":"b_none","oxy-mega-dropdown_slug_oxymegadropdowninner___custom_dropdown_width":"360","oxy-mega-dropdown_dropdown_relative_positioning":"link","oxy-mega-dropdown_-oxy-mega-dropdown-content_flex_flex-direction":"column","aos-enable":"false","aos-type":"flip-down","oxy-mega-dropdown_hashlink":"oxy_base64_encoded::L3NlYXJjaC1lbmdpbmUtb3B0aW1pemF0aW9uLWFuZC1tYXJrZXRpbmctbGFzLXZlZ2FzLw==","oxy-mega-dropdown_slug_oxymegadropdownicon_font_size":"0"},"media":{"phone-landscape":{"original":{"oxy-mega-dropdown_slug_oxymegadropdowniconsvg_transform:rotate":"270","oxy-mega-dropdown_slug_oxymegadropdownlinkoxymegadropdowninneropenoxymegadropdowniconsvg_transform:rotate":"0","oxy-mega-dropdown_slug_oxymegadropdowniconsvg_transition_duration":"400"}}},"classes":{"0":"mega-header-item"}}'_OXY_CLOSING_BRACKET__OXY_OPENING_BRACKET_/oxy-mega-dropdown_OXY_CLOSING_BRACKET__OXY_OPENING_BRACKET_oxy-mega-dropdown ct_sign_sha256='f7ef418f448ac3d1684c16d9e696484597ebbb46f0a9c170fe974525fbda3d72' ct_options='{"ct_id":502,"ct_parent":375,"selector":"-mega-dropdown-502-13","original":{"oxy-mega-dropdown_link_text":"oxy_base64_encoded::UG9ydGZvbGlv","oxy-mega-dropdown_hashlink":"oxy_base64_encoded::L3BvcnRmb2xpbw==","oxy-mega-dropdown_slug_oxymegadropdownicon_font_size":"0"},"activeselector":false}'_OXY_CLOSING_BRACKET__OXY_OPENING_BRACKET_/oxy-mega-dropdown_OXY_CLOSING_BRACKET__OXY_OPENING_BRACKET_oxy-mega-dropdown ct_sign_sha256='1f873dd577dc97265fc1393a312bd112f1e4d68b4d26da056f2de57cf37c9644' ct_options='{"ct_id":506,"ct_parent":375,"selector":"-mega-dropdown-506-13","original":{"oxy-mega-dropdown_link_text":"oxy_base64_encoded::QmxvZw==","oxy-mega-dropdown_hashlink":"oxy_base64_encoded::L2Jsb2c=","oxy-mega-dropdown_slug_oxymegadropdownicon_font_size":"0"},"activeselector":false}'_OXY_CLOSING_BRACKET__OXY_OPENING_BRACKET_/oxy-mega-dropdown_OXY_CLOSING_BRACKET__OXY_OPENING_BRACKET_oxy-mega-dropdown ct_sign_sha256='5a5d8ee9e8f4ea98ce6634f379d92a0bf84958f892b065444d1f4c13330ef088' ct_options='{"ct_id":508,"ct_parent":375,"selector":"-mega-dropdown-508-13","original":{"oxy-mega-dropdown_link_text":"oxy_base64_encoded::QWJvdXQ=","oxy-mega-dropdown_hashlink":"oxy_base64_encoded::L2Fib3V0LW91ci13ZWItZGVzaWduLW1hcmtldGluZy1maXJtLWFuZC10ZWFt","oxy-mega-dropdown_slug_oxymegadropdownicon_font_size":"0"},"activeselector":false}'_OXY_CLOSING_BRACKET__OXY_OPENING_BRACKET_/oxy-mega-dropdown_OXY_CLOSING_BRACKET__OXY_OPENING_BRACKET_oxy-mega-dropdown ct_sign_sha256='f3d33c15ea4e290c195a079ffc92a69c0d2593ca09542200f7f1ab4446304c54' ct_options='{"ct_id":511,"ct_parent":375,"selector":"-mega-dropdown-511-13","original":{"oxy-mega-dropdown_dropdown_elements":"none","oxy-mega-dropdown_link_text":"oxy_base64_encoded::QXBwb2ludG1lbnQ=","oxy-mega-dropdown_hashlink":"oxy_base64_encoded::L2NvbnRhY3Q="},"activeselector":false}'_OXY_CLOSING_BRACKET__OXY_OPENING_BRACKET_/oxy-mega-dropdown_OXY_CLOSING_BRACKET__OXY_OPENING_BRACKET_/oxy-mega-menu_OXY_CLOSING_BRACKET_

4 Custom Code Snippets For WordPress

Published On:
Reading Time:

When building a website and the customer needs a bit of custom functionality added to it, most designers look for a plugin to assist in this process. However, sometimes it is easier and more convenient to simply add a snippet of code instead of adding the dreaded just one more plugin problem. For using this you have 2 different options, you can either add these codes to your functions.php file or you can use a plugin the two best ones are Code Snippets and Advanced Scripts. Now let's jump right in!

1. Automatically Empty Trash

This snippet will automatically empty your WordPress trashcan after a specified amount of time. If you need to change it from weekly then simply change the "7" to something else like "1" to make it daily. This is useful for WooCommerce products, old blog posts and other similar scenarios in which constantly emptying the trash is too burdensome.

// automatically empty trash weekly 
define( 'EMPTY_TRASH_DAYS', 7 );
PHP

2. Get Home URL

This is useful if you are building a website on a sub-directory setup and you want the user to be able to click on the logo and take them home. An example of this scenario is if I was building a website on https://sigma1.com/new-website if I simply set the logo link wrapper to "/" it will take them to https://sigma1.com and not the homepage of https://sigma1.com/new-website. To prevent hard-coding these situations you would need to use this PHP function:

function sigma1_get_home_url() {
    return  get_home_url();   
}
PHP

Or you can use it in practice like this:

<?php echo get_home_url(); ?>
PHP

Credit: WordPress Developer Handbook

3. Lock Your WordPress Site

Sometimes when working on a client's website we want to lock the entire website to prevent people from looking at it while under development. There are tons of plugins that perform this function, but we are trying to avoid using plugins! Here is the code:

// Redirect users who arent logged in...
function members_only() {
    global $pagenow;
    // Check to see if user in not logged in and not on the login page
    if( !is_user_logged_in() && $pagenow != 'wp-login.php' )
          auth_redirect();
}
add_action( 'wp', 'members_only' );
PHP

4. Change The Logo On Your WordPress Login Page

function my_login_logo_one() { 
?>

<style>
body.login div#login h1 a {
 background-image: url(http://localhost/wordpress/one.jpeg);  //Add your own logo image in this url 
padding-bottom: 30px; 
} 
</style>

<?php
} add_action( 'login_enqueue_scripts', 'my_login_logo_one' );
PHP
_OXY_OPENING_BRACKET_oxy-table-of-contents ct_sign_sha256='df0ed18cd3a61e22618d95da83db86b8d997ad5c0f39f039c6603d7eb00ff1f2' ct_options='{"ct_id":205,"ct_parent":208,"selector":"-table-of-contents-205-104","original":{"oxy-table-of-contents_heading_selectors":"h2,h3,h4","oxy-table-of-contents_content_selector":".blog-text","oxy-table-of-contents_title_tag":"p","oxy-table-of-contents_-oxy-table-of-contents-title_typography_font-weight":"600","oxy-table-of-contents_-oxy-table-of-contents-title_typography_font-size":"24","oxy-table-of-contents_slug_oxytableofcontentslinkisactivelink_color":"color(16)","oxy-table-of-contents_maybe_autoid":"true","oxy-table-of-contents_smooth_scroll_offset":"150","oxy-table-of-contents_maybe_auto_link":"false","oxy-table-of-contents_heading_link_icon":"FontAwesomeicon-question-circle-o","oxy-table-of-contents_main_title_margin_margin-bottom":"0","oxy-table-of-contents_main_title_margin_margin-top":"0","globalconditions":{"0":{"name":"Post Tag","operator":0,"value":"dG9j","searchValue":"dG9j"}},"oxy-table-of-contents_list_item_padding_padding-bottom":"10","oxy-table-of-contents_collapse_depth":"0","oxy-table-of-contents_context_type":"border","background-color":"color(7)","z-index":"99999","oxy-table-of-contents_slug_oxytableofcontentstitle_color":"color(16)","oxy-table-of-contents_slug_oxytableofcontentslink_color":"color(6)","oxy-table-of-contents_collapsed_below":"page-width"},"activeselector":false,"classes":{"0":"c-margin-bottom-m"},"media":{"tablet":{"original":{"display":"none"}}}}'_OXY_CLOSING_BRACKET__OXY_OPENING_BRACKET_/oxy-table-of-contents_OXY_CLOSING_BRACKET_
Sigma 1 Logo

Signup For Our Newsletter

Stay up to date with the newest trends in technology, exclusive offers & discounts from our company, and new products and services that we are offering.

Want to Hire Us For Your Next Project?

We work with all different types of companies from around the world with one goal in mind - to help them grow their brand and acquire new customers.
Contact Us

When building a website and the customer needs a bit of custom functionality added to it, most designers look for a plugin to assist in this process. However, sometimes it is easier and more convenient to simply add a snippet of code instead of adding the dreaded just one more plugin problem. For using this you have 2 different options, you can either add these codes to your functions.php file or you can use a plugin the two best ones are Code Snippets and Advanced Scripts. Now let's jump right in!

1. Automatically Empty Trash

This snippet will automatically empty your WordPress trashcan after a specified amount of time. If you need to change it from weekly then simply change the "7" to something else like "1" to make it daily. This is useful for WooCommerce products, old blog posts and other similar scenarios in which constantly emptying the trash is too burdensome.

// automatically empty trash weekly 
define( 'EMPTY_TRASH_DAYS', 7 );
PHP

2. Get Home URL

This is useful if you are building a website on a sub-directory setup and you want the user to be able to click on the logo and take them home. An example of this scenario is if I was building a website on https://sigma1.com/new-website if I simply set the logo link wrapper to "/" it will take them to https://sigma1.com and not the homepage of https://sigma1.com/new-website. To prevent hard-coding these situations you would need to use this PHP function:

function sigma1_get_home_url() {
    return  get_home_url();   
}
PHP

Or you can use it in practice like this:

<?php echo get_home_url(); ?>
PHP

Credit: WordPress Developer Handbook

3. Lock Your WordPress Site

Sometimes when working on a client's website we want to lock the entire website to prevent people from looking at it while under development. There are tons of plugins that perform this function, but we are trying to avoid using plugins! Here is the code:

// Redirect users who arent logged in...
function members_only() {
    global $pagenow;
    // Check to see if user in not logged in and not on the login page
    if( !is_user_logged_in() && $pagenow != 'wp-login.php' )
          auth_redirect();
}
add_action( 'wp', 'members_only' );
PHP

4. Change The Logo On Your WordPress Login Page

function my_login_logo_one() { 
?>

<style>
body.login div#login h1 a {
 background-image: url(http://localhost/wordpress/one.jpeg);  //Add your own logo image in this url 
padding-bottom: 30px; 
} 
</style>

<?php
} add_action( 'login_enqueue_scripts', 'my_login_logo_one' );
PHP
Sigma 1 Logo

Signup For Our Newsletter

Stay up to date with the newest trends in technology, exclusive offers & discounts from our company, and new products and services that we are offering.

Want to Hire Us For Your Next Project?

We work with all different types of companies from around the world with one goal in mind - to help them grow their brand and acquire new customers.
Contact Us
Luke handles all the fun stuff for our clients like database administration, server management, and API integrations. He's a 3 time rowing world champion and currently earning his PhD in Chemical Engineering.

Leave a Reply

Your email address will not be published. Required fields are marked *

Leave a Reply

Your email address will not be published. Required fields are marked *