Home Blog

Removing WordPress Branding from your site

0

If you are a developer sometimes you never want to tell your clients if you are using WordPress, and you would prefer to remove the WordPress branding from your client’s website.

You can use following snippets:

  • To remove WP logo on top admin bar

  • To modify WordPress admin footer text “Thank you for creating with WordPress”:

 

Do not forget to add this code to your themes functions.php file.

Adding custom admin bar menu item

0

Sometimes we need to have a custom admin bar menu item to be added so that we can have an ease of access to a specific page.

I have come up with a simple and efficient solution for that. Here I am assuming if you need a shortcut to WP Super Cache page where you can easily clear the cache.

We will check whether user is already admin

if(!is_super_admin() || !is_admin_bar_showing()) return;

Check if WP Super Cache plugin is active

if ( is_plugin_active( 'wp-super-cache/wp-cache.php' ) ) {

You can always replace the 'wp-super-cache/wp-cache.php' with any plugin for which you would like to check if plugin exist, if your menu is not based on any plugin you can remove the else condition.

If you simply would like to have menu added without any dependency on the plugin you can use:

This will simply add the admin bar menu entry with the title ‘My Custom link’.

Do not forget to add this code to your themes functions.php file.

Resolving Access Control Allow Origin Error using Proxy

0

Many of us might have faced problem while sending ajax request to an external URL. I have tried to resolve this issue by creating a proxy in PHP and using CRON to access such URL.

The problem:

 

 

Even with most common ajax request like this

We might end up with ‘Access-Control-Allow-Origin’ header error.

To allow this request made by stackoverflow.com the server of google.com must return ‘Access-Control-Allow-Origin’ as http://www.stackoverflow.com.

The Solution

To resolve this issue we will try use curl using PHP as a proxy to get required data. Your required data could be the HTML code of the site to extract some part of content or you want to know the HTTP status code for your request.

We will show you how we can proxy through PHP to get the desired result. Lets create testurl.php file first:

We will be taking website URL from $_GET  method of PHP and store it in a variable and initialize the curl.

curl_setopt($ch, CURLOPT_HEADER, true)  will get the headers.

curl_setopt($ch, CURLOPT_NOBODY, false); will get the full body which can be processed as required.

We will now save the result in our array and echo it as json. The PHP will output us a JSON which can be processed by our Ajax request.

At front end we will require jQuery, you can import it as

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js" charset="utf-8"></script>

Now you can put your ajax request to get the response code:

Make sure you have placed the testurl.php file that we created above in your public_html or www directory of your server.

You can customize your output for each responseCode  by assigning some task.

Alternatively, If you want to get the HTML replace result.respcode  with result.html and you can process it as per your requirement.