How to Perform an Action Only Once in WordPress

The add_action function is the main function to use when creating WordPress plugins. You mainly use it for executing code at various run time points within WordPress. With this function, you can create shortcodes, enqueue scripts, styles, modify post titles and contents and lots more. How does this work? If you explode the core code of WordPress,Read the Rest…

Converting Relative URLs to Absolute URLs in PHP

We needed to convert relative URLs to absolute URLs inside CSS files for our upcoming plugin Combinator. There are a lot of code floating online that partially worked. The one that was closest was from http://99webtools.com/blog/convert-relative-path-into-absolute-url/. Here’s the reworked version that works great in PHP 5.3+ function rel2abs( $rel, $base ) { // parse baseRead the Rest…

How to Use the Javascript YouTube API Across Multiple Plugins

When using the YouTube API, you are required to create the function onYouTubePlayerAPIReady. There is a huge problem with this. If you have multiple WordPress plugins that use the YouTube API, that means that you have multiple declarations of onYouTubePlayerAPIReady. Multiple declarations in Javascript mean that previous onYouTubePlayerAPIReady functions get overwritten and will never beRead the Rest…

WordPress: How to Add a Button in the Admin Bar

This snippet will add a button on the admin bar: add_action( ‘admin_bar_menu’, array( $this, ‘addToggleButton’ ), 99 ); public function addToggleButton( $adminBar ) { $args = array( ‘id’ => ‘my_button’, ‘title’ => ‘My Button’, ‘href’ => ‘#’, ‘meta’ => array( ‘class’ => ‘my_class’, ‘onclick’ => ‘alert(“I was clicked”)’, ), ); $adminBar->add_node( $args ); }

Image Dimensions Get Lost when JetPack’s Photon is Activated

Jetpack issue submitted: https://github.com/Automattic/jetpack/issues/2281 If you do this: $attachmentImage = wp_get_attachment_image_src( 1234, ‘full’ ); $url = $attachmentImage[0]; $width = $attachmentImage[1]; $height = $attachmentImage[2]; $width and $height should give out the image dimensions, but when Photon is activated, both don’t get returned. The workaround for this is discussed here:https://wordpress.org/support/topic/wp_get_attachment_image_src-changed?replies=5#post-3950371 The workaround is to get the dimensions withoutRead the Rest…