https://fisherinc.co.uk/wp-content/uploads/10-usefull-functions3.png

10+ Really Useful WordPress Functions

  • Blog
  • 21/02/17
  • 10:30 AM
  • AMP
Fisher INC ltd 10+ Really Useful WordPress Functions 21/02/17 Functions… Functions play a big part in how your WordPress theme works as its performs as a plugin would. You can add code snippets to improve the functionality and features of your site, you can add your own functions, call PHP functions […]

Functions…

Functions play a big part in how your WordPress theme works as its performs as a plugin would.

You can add code snippets to improve the functionality and features of your site, you can add your own functions, call PHP functions or hook into a WordPress function.

It really is a useful file and here is some of my most used WordPress snippets to help me solve problems I face from time to time.

I know that many people would say that there are plugins to do these functions, Yes there are, but less is more, if its only 8 lines of code that you can easily paste in the functions file then why use a plugin.

So lets begin.


Add 3 custom sidebars

Adds 3 custom sidebar for you to use in the widget section of WordPress. simply remove / add as many as you need. (register_sidebar codex)


Add a custom menu

Adds a custom menu to wordpress which you can then use in your widgets. (register_nav_menu codex)


Add a settings page

Adds a settings page to the settings panel in WordPress with a textbox setting to get you started. (add_submenu_page codex) (Options Menu Video Tutorial) (Settings Video Tutorial)


Add custom CSS & JS scripts to the header or footer

Remember to create a main.css file and scripts.js file in your theme directory and update the directory paths. (wp_enqueue_style codex) (Video Tutorial)


Add google analytics to header

Add that precious tracking code to the header of your site with ease.  (wp_head codex)


Add a custom shortcode

Add a custom shortcode to do what you want with the one below shows a h1 title and a h3 subtitle. (add_shortcode codex) (Video Tutorial)


Remove orphan words

Puts a space between the second to last word so no paragraph ends with one word on a new line, not really a function more JavaScript but still useful


Echo theme / child / plugin directory

Useful when your enqueueing scripts or when your referencing an image in your theme directory.

Theme / Child Directory – /wp-content/themes/myTheme

Plugin Directory – /wp-content/plugins/


Conditional header tag.

Show something on one page but not the others? run scripts on the home page? make a certain page a different colour?

All can be achieved with conditional tags, they are used to do exactly that, run a specific piece of code on a specific post or page.


Add no follow to all external links

For SEO useful if you want to make sure Robots stay on your site and dont drift off somewhere you dont want them to go.


Echo Yoast Description & Keyword

For SEO echo the contents of the Yoast meta boxes on the post or page, using the below snippets.

Will Require a bit of PHP knowledge

Echo Focus Keyword

Echo Meta Description

If you have any problems or questions please let me know in the comments and I will happily assist.

Leave a Reply

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

*

*

*

*