Making a plugin

Community Forums Forums General Discussion Making a plugin

This topic is: not resolved

This topic contains 4 replies, has 2 voices, and was last updated by  AC 1 year, 9 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #19630

    AC
    Blocked
    Post count: 7712

    I saw on here on somewhere, where it said to “add this you the bottom of your functions.php file or create a plugin.” I cannot find this now, but… how do you take a code like that and create a plugin? Sometimes, I get three difference chunks of code to add to the functions… but if there was a way to create this plugin they referred to, I’d love to do that – learn how to do something new. I learn from SP and the people on here. It’s like going to school.

    #19681

    Bill Murray
    Participant
    Post count: 575

    Here’s a link to a simple plugin we created for a user: http://wpp.im/d9

    For a simple solution:

    1) Change the plugin name to the name you want
    2) Change the author, author website, version, license as you see fit
    3) Put it either in the wp-content/plugins folder or a sub-folder of that folder
    4) Change the code as you see fit
    5) Refresh your plugin list and activate/deactivate


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    #19684

    AC
    Blocked
    Post count: 7712

    Wow, that’s great Bill!!! Thank you so much. Let me ask this.. I see different things in there. So, I can add different things in the one plugin or do I need to create one plugin for each function. For example, if I wanted to use the snippet to unregister a couple template layouts – I’d create one for that. And if I wanted to say, reverse the navigation – I’d create one and add that code to that? Or add everything into one plugin?

    #19691

    Bill Murray
    Participant
    Post count: 575

    You can put whatever you want in 1 plugin provided that you keep in mind the entire plugin code is run. If you want to always unregister some layouts and always reverse the navigation, you could create a plugin called “Anita’s Favorite Setup” and have it do both. Certainly, you get some control with conditional tags, so if you only wanted to reverse the navigation if a certain Genesis child theme were active, you could put that code in an appropriate conditional tag. In other words, once activated, the plugin code is always run, so unless you control the impact with conditional tags, it will execute.

    A further note…the plugins folder supports searching in sub-folders, so my instruction above on the ability to use a sub-folder applies to the plugins folder. The mu-plugins folder in a multisite install does NOT support subfolders, so that comment doesn’t apply.

    Plugins execute BEFORE the code in functions.php, so you can run into situations where your plugin does something but a child theme setup undoes it, leading you to incorrectly conclude you had the wrong plugin code. In these cases, you have to create a function that contains your commands (such as a remove action) and add that function to a hook (such as init) that comes AFTER functions.php is processed. That may sound like gibberish now, but if you ever find that code you think should work isn’t behaving as you’d expect when put into a plugin, check the child theme’s funcitons.php and revisit this paragraph.

    If you do a google search on “wordpress custom functionality plugin” you’ll find many links on the topic.


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    #19699

    AC
    Blocked
    Post count: 7712

    Thanks again. This is my homework for the evening. Gonna go take the dog out, make some supper and then onto PLUGINS!!!

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Making a plugin’ is closed to new replies.