The WordPress drag-and-drop menus make it easy to build a custom menu for your website, but adding a login/logout link requires a little PHP code. It’s very simple though, and easy to add to any theme.
Posts tagged “php”
Add an external link to the WordPress admin menu
WordPress has a good API for adding admin menu items. Unfortunately, it doesn’t allow you to specify a direct link to something, only a “slug” that links your menu item to a callback function to run when your menu item is selected. But fortunately, there’s a hack.
Custom post names for WordPress custom post types
When you edit a new post, page, or an object of a custom post type, WordPress generates a slug or post name that will be used in its permalink. It derives the post name from the title you gave it. Sometimes, however, you want the post name to have a little more information in it.
WordPress is_ssl() doesn’t work behind some load balancers
WordPress has a function is_ssl()
that it uses to check whether a page is loaded with the HTTPS protocol, so that it can use the same protocol to load scripts, stylesheets, and other assets. It relies on the web server giving it a couple of clues, but when your website is hosted behind a load balancer, those clues aren’t always available. In particular, websites hosted by Network Solutions get no clues at all when pages are loaded over HTTPS.
Stop Events Manager from cropping thumbnails
Events Manager gives you a special placeholder that you can put into its templates, for inserting the event’s “featured image” into lists and single event pages. If you want to insert a thumbnail, it uses the timthumb script to create one on the fly — but it crops that thumbnail. Here’s how to use the WordPress uncropped thumbnail (or any registered image size).
Events Manager locations map with directions
Events Manager is my events and bookings plugin of choice for WordPress, because it is very flexible, easy to integrate into a theme, and has hooks galore for customising to suit almost any requirement. Its location map doesn’t offer a way to provide directions, however. So, here’s how to replace the Events Manager locations map with WP Flexible Map and get a directions link on location pages.
Subscribe to mailing list in WooCommerce checkout
A common requirement when building an online shop is to ask shoppers if they’d like to subscribe to shop’s newsletter, so that they can be updated when new products and specials are available. WooCommerce doesn’t come with such things as part of their standard checkout form, but with a few handy hooks, it’s very easy to add.
Repair WordPress image meta
There are times when things just go wrong. I had one of those times the other day. The pressure was on to deliver a project, and there were bits of PHP and CSS and JavaScript flying everywhere here at WebAware Central. And so it happened: I wiped the image attachment meta data in the WordPress database.
Get custom fields for WordPress post
WordPress lets you store custom fields on your posts (and pages, and custom post types that allow it). However, it gives them to you in a rather inconvenient manner, with your values mixed in with its own special fields and any plugin’s special fields, and with values in an array. Here’s how to easily deal with that.
Add shortcodes to WordPress Text widgets
WordPress comes with a few standard widgets, one of which is the Text widget. It’s a fairly versatile widget that lets you add simple text or even HTML into any widget zone on your website. One thing it doesn’t let you add is shortcodes. But it’s very easy to allow the Text widget to accommodate shortcodes too.
Stop turning off CURLOPT_SSL_VERIFYPEER and fix your PHP config
As Pádraic Brady points out in a recent article about PHP security, there’s a whole lot of misinformation about how to deal with the error “SSL certificate problem, verify that the CA cert is OK” from curl. Nearly everyone advises that you turn CURLOPT_SSL_VERIFYPEER off (in fact, countless comments on the PHP manual page for curl_setopt tell you this). This is bad, because it allows your nice, encrypted stream of confidential data to be silently highjacked by a bad guy. Don’t do that! Instead, just fix your PHP installation so that it doesn’t get that error.
Filtering the output of WordPress widgets
Probably the best thing about WordPress, from my perspective as a developer, is its hooks. It has filter and action hooks for nearly everything, which means I can easily customise a WordPress website to meet pretty much any requirements thrown at me. Well, nearly any. Except widgets.