Web & Software Developer

Archive for “WordPress Code Snippets”

WordPress tutorials, help, and code snippets to help you design and customize your own WordPress site.

Insert Google Adsense Native In-article ad on Regular WordPress Posts, and AMP ad on AMP pages

This is one code snippet to insert Google Adsense ads on all your WordPress posts, both regular and AMP. (This code works with the official AMP for WordPress plugin.) This one code snippet will automatically insert one Google Adsense ad after the first paragraph of every post. On regular posts, it will insert a “Native … Read more →

Show WP Admin Notice With Pure JavaScript

This adds a dismissible admin notice to the WP admin with pure JavaScript. No jQuery or other dependencies. The admin notice will have a Dismiss icon just like the regular WP admin notices. When the icon is clicked, the message will go away. This admin notice will have a blue left border which is given … Read more →

Run Code Only Once in WordPress

You may have a function or some code that you only want to run one time on your WordPress site. You may notice that functions hooked on to admin_init can be fired twice. Here is quick way to run your code only once. This will guarantee that it runs one, and only one, time. Mandatory … Read more →