Intro to Wordpress: Editing functions.php and WP Plugins
I am studying Wordpress and PHP with @skillcrush, in this article we cover editing functions.php and using WP plugins!
I am learning with Skillcrush. Please check them out and sign up if you're looking to break into tech!
Receive $250 off your course by using the link above. Use the coupon code: TWIXMIXY
NOTE: this discount is for Break Into Tech + Get Hired package exclusively.
It's the same program I am participating in!
🙌 Greetings travelers! We are studying Wordpress and PHP with Skillcrush. In this article we cover editing functions.php and using WP plugins.
🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩⬜⬜⬜⬜⬜⬜ 70% DONE
Well… I made the decision! I’m going to enroll in an immersive bootcamp for the remainder of the year. 📚💻🖨☕️📖📓📚📝✍️📜✒️🎓
Yesterday I was offered a job role and it was actually a great package all in all. Much better than anything I’ve received previously. However, I just knew that I couldn’t accept it. My heart is in this work now. The work of learning how to code and making this pivot in my career.
Currently I’m narrowing down the programs that I’m interested in and speaking with the enrollment staff to try and make the best choice for myself.
Stay tuned. I’ll very likely be making an announcement within the next week!
You can subscribe without signing up for a substack account! Also just select “None” when subscribing. All the content from my learning journey is free.
Intro to functions.php file
According to Skillcrush the widgets are managed in the functions.php file. They provide us with code to activate widgets.
// Register widget area
function skillcrushstarter_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar 1', 'skillcrushstarter' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar.', 'skillcrushstarter' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'skillcrushstarter_widgets_init' );
This is an explicitly Skillcrush created widget initiator.
functions.php is not a required theme file, but it can be one of the most powerful files.
This can be used to change pretty much any default WP setting.
Things to remember about functions.php:
functions.php has to be named functions.php - no other nomenclature will work.
Functions that are defined in functions.php cannot be defined anywhere else in the template files. Function names cannot be repeated (so if WP already defines one, you can’t use it)
Order of the functions doesn’t matter, but nesting functions can mess up and cause PHP errors.
Functions vary from theme to theme. They are defined in the functions.php file within a theme.
Time to create new functions
We’re going to make a copy of the content.php and name it content-blog.php
Then we will change
<?php the_content(); ?>
to
<?php the_excerpt(); ?>
Next we will edit our index.php file. Adding -blog
to make content
into content-blog
.
Now our posts are shortened on the main blog page.
Now we want to add the ability for us to “read more” and we do that through adding a function to the functions.php.
// Changes excerpt symbol
function custom_excerpt_more($more) {
return '...<div class="read-more"><a href="'. get_permalink() . '"><span>Read more</span> »</a></div>';
}
add_filter('excerpt_more', 'custom_excerpt_more');
For our next challenge we’re going to add featured images to the blog page.
In the functions.php file we are given there is already a piece of code to enable featured images.
// Post thumbnails support
add_theme_support('post-thumbnails');
We need a call for the featured image and where we want it to appear. We’re going to call it to display on the content-blog.php so it will display on our blog page.
<?php if ( has_post_thumbnail() ) : ?>
<figure><?php the_post_thumbnail('full'); ?></figure>
<?php endif; ?>
Now we need to set a featured image to our blog post through the WP dashboard.
Winona!! What a great feature image.
🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩⬜⬜⬜⬜⬜ 75% DONE
All about plugins
I definitely utilized plugins a lot when I previously developed website for customers to make them meet the needs of the project I was working on. I’m looking forward to seeing what Skillcrush can enlighten me about them.
DRY = Do not Repeat Yourself
Basically meaning, why reinvent the wheel if this is something that’s already been done? This is a time and effort saving measure but using others plugins.
There are lots of great free plugins out there and Skillcrush gives a list of their recommended ones. I’m going to keep pushing on and see what new knowledge we can learn. If I need one of them for the course I’ll circle back.
From the dashboard there is a library that you can search and find plugins you may want to install.
However there is a manual way to install plugins for any that you may find out on the web.
In this method you download the plugin and place in the wp-content > plugins folder.
Then you’ll see it in your dashboard and can activate it.
From there with any plugin you can edit the settings, add it as a widget (if it’s that type of plugin) and customize it for your WP website.
Here is a basic plugin, utilized for internal stat tracking.
Paid Plugin Benefits
Support - issues, errors, user experience etc.
Updates - someone is updating and maintaining the code
Time - saving the time of creating your own
Supporting other developers for their hard work!
Skillcrush goes on to recommend their top paid for plugins.
I definitely recall paying for some of these back in the day!! Sometimes time is money.
Plugin Problems
Plugin doesn’t activate and gives an error
Activating plugin completely breaks the website
Ugly PHP error shows up on all website pages - something isn’t working!
Since this is a community, it’s best to make the author aware of the issues. Most likely you’ll have to remove/delete the plugin and find one that will actually work.
Maintaining Plugins
Update!! Newer versions contain fixes and other features
Keeping up on your own website cleanliness - review plugins and deactivate outdated ones
Delete any plugins you definitely don’t need.
That’s it for functions.php and plugins for now!!
We are now…
🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩⬜⬜⬜⬜ 80% DONE
with this course! Can we wrap it up by tomorrow?? Probably not because I need to grocery shop and make bread. But maybe I can do it this weekend. Stay tuned!
What did you think? Leave me a comment and share!