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 →

How To Use a Shortcode in WordPress 5.0 and higher, The New WordPress Editor (Gutenberg)

If you’re using WordPress 5.0 or higher with the new WordPress editor, also known as Gutenberg, and you will use shortcodes a little differently than before. Instead of just pasting or typing the shortcode, the new Gutenberg WordPress editor requires 5 steps. (Yes, this seems very backwards.) First, click on the “plus” icon to add … 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 →