{"id":2883,"date":"2016-09-29T16:00:07","date_gmt":"2016-09-29T13:00:07","guid":{"rendered":"https:\/\/themeisle.com\/blog\/?p=2883"},"modified":"2023-08-18T12:33:46","modified_gmt":"2023-08-18T09:33:46","slug":"code-snippets-for-wordpress","status":"publish","type":"post","link":"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/","title":{"rendered":"10 Useful Code Snippets for WordPress Users"},"content":{"rendered":"<p>We know that plugins can be used to extend the functionality of WordPress. But what if you can do some smaller things in WordPress without installing them? Say, you dislike the admin bar at the top and wish to eliminate it? Yes, that can be accomplished by means of code snippets for WordPress.<\/p>\n<div class=\"su-row\">\n<div class=\"su-column su-column-size-1-2\"><div class=\"su-column-inner su-u-clearfix su-u-trim\">\n<p>Basically, code snippets for WordPress are used to do certain actions that might otherwise require a dedicated smaller plugin. Such code snippets are placed in one of the WordPress core or theme files (generally the <em>functions.php<\/em> file of your theme).<\/p>\n<\/div><\/div>\n<div class=\"su-column su-column-size-1-2\"><div class=\"su-column-inner su-u-clearfix su-u-trim\">\n\n\t\t<div class='ti-tweet-clear'><\/div>\n\t\t\t<div class='ti-tweet_wrapper'>\n\t\t    \t<div class='ti-tweet_text'>\n\t\t    \t\t<a href='https:\/\/twitter.com\/share?text=10+useful+%23code+%23snippets+for+%23WordPress+users+%F0%9F%96%A5%EF%B8%8F&via=themeisle&related=themeisle&url=https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/' target='_blank' rel='nofollow'>10 useful #code #snippets for #WordPress users \ud83d\udda5\ufe0f<\/a>\n\t\t    \t<\/div>\n\t\t    \t<div class='ti-tweet_sharebtn'>\n\t\t    \t<a href='https:\/\/twitter.com\/share?text=10+useful+%23code+%23snippets+for+%23WordPress+users+%F0%9F%96%A5%EF%B8%8F&via=themeisle&related=themeisle&url=https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/' target='_blank' rel='nofollow'>Click To Tweet \n\t\t    \t\t<span><\/span>\n\t\t    \t<\/a>\n\t\t    <\/div>\n\t\t<\/div>\n<\/div><\/div>\n<\/div>\n<p><!--more--><\/p>\n<p>In this article, we will share \u23e9 <a href=\"#useful-code-snippets\">ten very useful code snippets<\/a> for WordPress users. We&#8217;ll then wrap it up by explaining \u23e9 <a href=\"#how-to-add-code-snippets-using-a-plugin\">how you can add these code snippets to your WordPress pages and posts<\/a> by using a free plugin.<br \/>\n<div class=\"su-divider su-divider-style-dotted\" style=\"margin:40px 0;border-width:1px;border-color:#999999\"><\/div>\n<h2 id=\"useful-code-snippets\">10 Useful Code Snippets for WordPress Users \ud83d\udcda<\/h2>\n<ol>\n<li><a href=\"#allow-contributors-to-upload-images\">Allow Contributors to Upload Images<\/a><\/li>\n<li><a href=\"#show-popular-posts-without-plugins\">Show Popular Posts Without Plugins<\/a><\/li>\n<li><a href=\"#disable-search-in-wordpress\">Disable Search in WordPress<\/a><\/li>\n<li><a href=\"#protect-your-site-from-malicious-requests\">Protect Your Site from Malicious Requests<\/a><\/li>\n<li><a href=\"#paginate-your-site-without-plugins\">Paginate Your Site Without Plugins<\/a><\/li>\n<li><a href=\"#disable-the-admin-bar\">Disable the Admin Bar<\/a><\/li>\n<li><a href=\"#show-post-thumbnails-in-rss-feed\">Show Post Thumbnails in RSS Feed<\/a><\/li>\n<li><a href=\"#change-the-author-permalink-structure\">Change the Author Permalink Structure<\/a><\/li>\n<li><a href=\"#automatically-link-to-twitter-usernames-in-content\">Automatically Link to Twitter Usernames in Content<\/a><\/li>\n<li><a href=\"#create-a-paypal-donation-shortcode\">Create a PayPal Donation Shortcode<\/a><\/li>\n<\/ol>\n<div class=\"su-divider su-divider-style-dotted\" style=\"margin:40px 0;border-width:1px;border-color:#999999\"><\/div>\n<h2>Word of Caution! \u270b<\/h2>\n<p>As you might have guessed, code snippets for WordPress, while really useful, tend to alter the default functionality. There can be a small margin of error with each snippet. Generally, such issues tend to arise due to incompatible plugins and\/or themes and tend to disappear once you <a href=\"https:\/\/themeisle.com\/blog\/remove-slow-wordpress-plugins\/\">eliminate the said theme\/plugin<\/a> or decide not to use the said snippet.<\/p>\n<p>However, to be on the safer side, be very sure to <a href=\"https:\/\/themeisle.com\/blog\/wordpress-backup-plugins-compared\/\">take proper backups of your WordPress website<\/a> before making any changes by means of snippets. Also, if you encounter any error or <a href=\"https:\/\/themeisle.com\/blog\/wordpress-performance\/\">performance issues<\/a>, rollback your site and check for any plugins or incompatible theme issues.<\/p>\n<p>Now, on to the code snippets for WordPress users!<br \/>\n<div class=\"su-divider su-divider-style-default\" style=\"margin:40px 0;border-width:15px;border-color:#4267cf\"><\/div>\n<h3 id=\"allow-contributors-to-upload-images\">1. Allow Contributors to Upload Images<\/h3>\n<p>By default, WordPress does not permit contributor accounts to upload images. You can, of course, promote that particular account to Author or Editor and this will give them the rights to upload and modify images, However, it will also grant them additional rights, such as the ability to publish their own articles (as opposed to submission for review).<\/p>\n<p>This particular code snippet allows contributor accounts to upload images to their articles, without granting them any additional privileges or rights. Paste it in the <em>functions.php<\/em> file of your theme:<\/p>\n<pre><code>if ( current_user_can('contributor') &amp;&amp; !current_user_can('upload_files') )\r\n \u00a0\u00a0\u00a0\u00a0add_action('admin_init', 'allow_contributor_uploads'); \u00a0\u00a0\u00a0\u00a0\u00a0\r\n \u00a0\u00a0\u00a0\u00a0function allow_contributor_uploads() {\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$contributor = get_role('contributor');\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$contributor-&gt;add_cap('upload_files');\r\n \u00a0\u00a0\u00a0\u00a0}<\/code><\/pre>\n<div class=\"su-divider su-divider-style-default\" style=\"margin:40px 0;border-width:15px;border-color:#4267cf\"><\/div>\n<h3 id=\"show-popular-posts-without-plugins\">2. Show Popular Posts Without Plugins<\/h3>\n<p>This one is a little trickier. However, if you are not too keen on installing an extra plugin to showcase popular posts (say, you have limited server memory or disk space), follow this snippet.<\/p>\n<p>Paste the following in <em>functions.php<\/em>:<\/p>\n<pre><code>function count_post_visits() {\r\n \u00a0\u00a0\u00a0if( is_single() ) {\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0global $post;\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$views = get_post_meta( $post-&gt;ID, 'my_post_viewed', true );\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if( $views == '' ) {\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0update_post_meta( $post-&gt;ID, 'my_post_viewed', '1' ); \u00a0\u00a0\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} else {\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$views_no = intval( $views );\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0update_post_meta( $post-&gt;ID, 'my_post_viewed', ++$views_no );\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n \u00a0\u00a0\u00a0}\r\n}\r\nadd_action( 'wp_head', 'count_post_visits' );<\/code><\/pre>\n<p>Thereafter, paste the following wherever in your template files that you wish to display the popular posts:<\/p>\n<pre><code>$popular_posts_args = array(\r\n \u00a0\u00a0\u00a0'posts_per_page' =&gt; 3,\r\n \u00a0\u00a0\u00a0'meta_key' =&gt; 'my_post_viewed',\r\n \u00a0\u00a0\u00a0'orderby' =&gt; 'meta_value_num',\r\n \u00a0\u00a0\u00a0'order'=&gt; 'DESC'\r\n);\r\n$popular_posts_loop = new WP_Query( $popular_posts_args );\r\n \u00a0while( $popular_posts_loop-&gt;have_posts() ):\r\n \u00a0\u00a0\u00a0$popular_posts_loop-&gt;the_post();\r\n \u00a0\u00a0\u00a0\/\/ Loop continues\r\nendwhile;\r\nwp_reset_query();<\/code><\/pre>\n<div class=\"su-divider su-divider-style-default\" style=\"margin:40px 0;border-width:15px;border-color:#4267cf\"><\/div>\n<h3 id=\"disable-search-in-wordpress\">3. Disable Search in WordPress<\/h3>\n<p>The <a href=\"https:\/\/themeisle.com\/blog\/improve-internal-search-in-wordpress\/\">search feature of WordPress<\/a> has been around for a long time. However, if your website does not need it, or you do not want users to &#8220;search&#8221; through your website for some reason, you can use this code snippet.<\/p>\n<p>Essentially, it is a custom function that simply nullifies the search feature. Not just the search bar in your sidebar or the menu, but the entire concept of native WP search is gone. Why can this be useful? Again, it can help if you are running your website on low spec server and do not have content that needs to be searched (probably you aren&#8217;t running a blog).<\/p>\n<p>Again, add this to the <em>functions.php<\/em> file:<\/p>\n<pre><code>function fb_filter_query( $query, $error = true ) {\r\nif ( is_search() ) {\r\n$query-&gt;is_search = false;\r\n$query-&gt;query_vars[s] = false;\r\n$query-&gt;query[s] = false;\r\n\/\/ to error\r\nif ( $error == true )\r\n$query-&gt;is_404 = true;\r\n}\r\n}\r\nadd_action( 'parse_query', 'fb_filter_query' );\r\nadd_filter( 'get_search_form', create_function( '$a', \"return null;\" ) );<\/code><\/pre>\n<div class=\"su-divider su-divider-style-default\" style=\"margin:40px 0;border-width:15px;border-color:#4267cf\"><\/div>\n<h3 id=\"protect-your-site-from-malicious-requests\">4. Protect Your Site from Malicious Requests<\/h3>\n<p>There are various ways to secure your website. You can install a security plugin, turn on a firewall or opt for a free feature such as Jetpack Protect that blocks brute force attacks on your website.<\/p>\n<p>The following code snippet, once placed in your <em>functions.php<\/em> file, rejects all malicious URL requests:<\/p>\n<pre><code>global $user_ID; if($user_ID) {\r\n \u00a0\u00a0\u00a0if(!current_user_can('administrator')) {\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (strlen($_SERVER['REQUEST_URI']) &gt; 255 ||\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0stripos($_SERVER['REQUEST_URI'], \"eval(\") ||\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0stripos($_SERVER['REQUEST_URI'], \"CONCAT\") ||\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0stripos($_SERVER['REQUEST_URI'], \"UNION+SELECT\") ||\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0stripos($_SERVER['REQUEST_URI'], \"base64\")) {\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0@header(\"HTTP\/1.1 414 Request-URI Too Long\");\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0@header(\"Status: 414 Request-URI Too Long\");\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0@header(\"Connection: Close\");\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0@exit;\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n \u00a0\u00a0\u00a0}\r\n}<\/code><\/pre>\n<div class=\"su-divider su-divider-style-default\" style=\"margin:40px 0;border-width:15px;border-color:#4267cf\"><\/div>\n<h3 id=\"paginate-your-site-without-plugins\">5. Paginate Your Site Without Plugins<\/h3>\n<p><a href=\"https:\/\/themeisle.com\/blog\/pagination-in-wordpress\/\">Good pagination<\/a> is very useful for allowing users to browse through your website. Rather than &#8220;previous&#8221; or &#8220;next&#8221; links. This is where another one of our code snippets for WordPress comes into play &#8211; it adds good pagination to your content.<\/p>\n<p>In <em>functions.php<\/em>:<\/p>\n<pre><code>global $wp_query;\r\n$total = $wp_query-&gt;max_num_pages;\r\n\/\/ only bother with the rest if we have more than 1 page!\r\nif ( $total &gt; 1 ) \u00a0{\r\n \u00a0\u00a0\u00a0\u00a0\/\/ get the current page\r\n \u00a0\u00a0\u00a0\u00a0if ( !$current_page = get_query_var('paged') )\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$current_page = 1;\r\n \u00a0\u00a0\u00a0\u00a0\/\/ structure of \"format\" depends on whether we're using pretty permalinks\r\n \u00a0\u00a0\u00a0\u00a0$format = empty( get_option('permalink_structure') ) ? '&amp;page=%#%' : 'page\/%#%\/';\r\n \u00a0\u00a0\u00a0\u00a0echo paginate_links(array(\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'base' =&gt; get_pagenum_link(1) . '%_%',\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'format' =&gt; $format,\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'current' =&gt; $current_page,\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'total' =&gt; $total,\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'mid_size' =&gt; 4,\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'type' =&gt; 'list'\r\n \u00a0\u00a0\u00a0\u00a0));\r\n}<\/code><\/pre>\n<div class=\"su-divider su-divider-style-default\" style=\"margin:40px 0;border-width:15px;border-color:#4267cf\"><\/div>\n<h3 id=\"disable-the-admin-bar\">6. Disable the Admin Bar<\/h3>\n<p>The WordPress Admin Bar provides handy links to several key functions such as the ability to add new posts and pages, etc. However, if you find no use for it and wish to remove it, simply paste the following code snippet to your <em>functions.php<\/em> file:<\/p>\n<pre><code>\/\/ Remove the admin bar from the front end\r\nadd_filter( 'show_admin_bar', '__return_false' );<\/code><\/pre>\n<div class=\"su-divider su-divider-style-default\" style=\"margin:40px 0;border-width:15px;border-color:#4267cf\"><\/div>\n<h3 id=\"show-post-thumbnails-in-rss-feed\">7. Show Post Thumbnails in RSS Feed<\/h3>\n<p>If you wish to show post thumbnail images in your blog&#8217;s RSS feed, the following code snippet for WordPress can be useful.<\/p>\n<p>Place it in your <em>functions.php<\/em> file:<\/p>\n<pre><code>\/\/ Put post thumbnails into rss feed\r\nfunction wpfme_feed_post_thumbnail($content) {\r\nglobal $post;\r\nif(has_post_thumbnail($post-&gt;ID)) {\r\n$content = '' . $content;\r\n}\r\nreturn $content;\r\n}\r\nadd_filter('the_excerpt_rss', 'wpfme_feed_post_thumbnail');\r\nadd_filter('the_content_feed', 'wpfme_feed_post_thumbnail');<\/code><\/pre>\n<div class=\"su-divider su-divider-style-default\" style=\"margin:40px 0;border-width:15px;border-color:#4267cf\"><\/div>\n<h3 id=\"change-the-author-permalink-structure\">8. Change the Author Permalink Structure<\/h3>\n<p>By default, WordPress shows author profiles as <code>yoursite.com\/author\/name<\/code>. However, you can change it to anything that you like, such as <code>yoursite.com\/writer\/name<\/code><\/p>\n<p>The following code snippet needs to be pasted in the <em>functions.php<\/em> file. Then, it changes the author permalink structure to &#8220;\/profile\/name&#8221;:<\/p>\n<pre><code>add_action('init', 'cng_author_base');\r\nfunction cng_author_base() {\r\n \u00a0\u00a0\u00a0global $wp_rewrite;\r\n \u00a0\u00a0\u00a0$author_slug = 'profile'; \/\/ change slug name\r\n \u00a0\u00a0\u00a0$wp_rewrite-&gt;author_base = $author_slug;\r\n}<\/code><\/pre>\n<div class=\"su-divider su-divider-style-default\" style=\"margin:40px 0;border-width:15px;border-color:#4267cf\"><\/div>\n<h3 id=\"automatically-link-to-twitter-usernames-in-content\">9. Automatically Link to Twitter Usernames in Content<\/h3>\n<p>This is especially useful if you are running a website that focuses a lot <a href=\"https:\/\/twitter.com\/themeisle\" target=\"_blank\" rel=\"noopener\">on Twitter<\/a> (probably a viral content site, etc.) The following code snippet for <em>functions.php<\/em> converts all @ mentions in your content to their respective Twitter profiles.<\/p>\n<p>For example, an @happy mention in your content will be converted to a link to the Twitter account &#8220;twitter.com\/happy&#8221; (&#8220;happy&#8221; being the username):<\/p>\n<pre><code>function content_twitter_mention($content) {\r\nreturn preg_replace('\/([^a-zA-Z0-9-_&amp;])@([0-9a-zA-Z_]+)\/', \"$1&lt;a href=\\\"http:\/\/twitter.com\/$2\\\" target=\\\"_blank\\\" rel=\\\"nofollow\\\"&gt;@$2&lt;\/a&gt;\", $content);\r\n}\r\nadd_filter('the_content', 'content_twitter_mention'); \u00a0\u00a0\r\nadd_filter('comment_text', 'content_twitter_mention');<\/code><\/pre>\n<div class=\"su-divider su-divider-style-default\" style=\"margin:40px 0;border-width:15px;border-color:#4267cf\"><\/div>\n<h3 id=\"create-a-paypal-donation-shortcode\">10. Create a PayPal Donation Shortcode<\/h3>\n<p>If you are using the PayPal Donate function to accept donations from your website&#8217;s visitors, you can use this code snippet to create a shortcode, and thus make donating easier. First, paste the following in your <em>functions.php<\/em> file:<\/p>\n<pre><code>function donate_shortcode( $atts, $content = null) {\r\nglobal $post;extract(shortcode_atts(array(\r\n'account' =&gt; 'your-paypal-email-address',\r\n'for' =&gt; $post-&gt;post_title,\r\n'onHover' =&gt; '',\r\n), $atts));\r\nif(empty($content)) $content='Make A Donation';\r\nreturn '&lt;a href=\"https:\/\/www.paypal.com\/cgi-bin\/webscr?cmd=_xclick&amp;business='.$account.'&amp;item_name=Donation for '.$for.'\" title=\"'.$onHover.'\"&gt;'.$content.'&lt;\/a&gt;';\r\n}\r\nadd_shortcode('donate', 'donate_shortcode');<\/code><\/pre>\n<p>Then, you can easily use the [donate] shortcode, such as:<\/p>\n<pre><code>[donate]My Text Here[\/donate]<\/code><\/pre>\n<div class=\"su-divider su-divider-style-dotted\" style=\"margin:40px 0;border-width:1px;border-color:#999999\"><a href=\"#\" style=\"color:#999999\">Go to top<\/a><\/div>\n<h2 id=\"how-to-add-code-snippets-using-a-plugin\">How to Add Code Snippets? \ud83e\udd14<\/h2>\n<p>As mentioned with each code snippet, you just need to add the said snippet to the required file. Mostly, you would only need to add code snippets to the <em>functions.php<\/em> file (in some cases, it can differ).<\/p>\n<p>However, what if you are just not comfortable editing your theme&#8217;s files? If that is the case, have no fear. The Code Snippets plugin can help you out!<\/p>\n<div class=\"wp-pic-wrapper align-center large\" style=\"margin:20px 0;\"><div class=\"wp-pic large plugin scheme2\"  id=\"wp-pic-code-snippets\" ><div class=\"wp-pic-large\" style=\"display: none;\">\n\t<div class=\"wp-pic-large-content\">\n\t\t<a rel=\"nofollow\" class=\"wp-pic-asset-bg\" href=\"https:\/\/wordpress.org\/plugins\/code-snippets\/\" target=\"_blank\" title=\"WordPress.org Plugin Page\">\n\t\t\t<img data-opt-id=1097485604  fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/ps.w.org\/code-snippets\/assets\/banner-772x250.png?rev=3147867\" alt=\"Code Snippets\" \/>\t\t\t<span class=\"wp-pic-asset-bg-title\"><span>Code Snippets<\/span><\/span>\n\t\t<\/a>\n\t\t<div class=\"wp-pic-half-first\">\n\t\t\t<a rel=\"nofollow\" class=\"wp-pic-logo\" href=\"https:\/\/wordpress.org\/plugins\/code-snippets\/\" style=\"background-image: url(https:\/\/ps.w.org\/code-snippets\/assets\/icon.svg?rev=2148878 );\" target=\"_blank\" title=\"WordPress.org Plugin Page\"><\/a>\n\t\t\t<p class=\"wp-pic-author\">Author(s):\t\t\t\t\t\t\t\t\t<a rel=\"nofollow\" href=\"https:\/\/profiles.wordpress.org\/codesnippetspro\/\">Code Snippets Pro<\/a>\n\t\t\t\t\t\t\t<\/p>\n\t\t\t<p class=\"wp-pic-version\"><span>Current Version:<\/span> 3.9.5<\/p>\n\t\t\t<p class=\"wp-pic-updated\"><span>Last Updated:<\/span> February 5, 2026<\/p>\n\t\t\t<p><a rel=\"nofollow\" class=\"wp-pic-dl-link\" href=\"https:\/\/downloads.wordpress.org\/plugin\/code-snippets.3.9.5.zip\" title=\"Direct download\">Direct Download<\/a><\/p>\n\t\t\t\t\t<\/div>\n\t\t<div class=\"wp-pic-half-last\">\n\t\t\t<div class=\"wp-pic-bottom\">\n\t\t\t\t<div class=\"wp-pic-bar\">\n\t\t\t\t\t<a rel=\"nofollow\" href=\"https:\/\/wordpress.org\/support\/view\/plugin-reviews\/code-snippets\" class=\"wp-pic-rating\" target=\"_blank\" title=\"Ratings\">\n\t\t\t\t\t\t94%<em>Ratings<\/em>\n\t\t\t\t\t<\/a>\n\t\t\t\t\t<a rel=\"nofollow\" href=\"https:\/\/downloads.wordpress.org\/plugin\/code-snippets.3.9.5.zip\" class=\"wp-pic-downloaded\" target=\"_blank\" title=\"Direct download\">\n\t\t\t\t\t\t1,000,000+<em>Installs<\/em>\n\t\t\t\t\t<\/a>\n\t\t\t\t\t<a rel=\"nofollow\" href=\"https:\/\/wordpress.org\/plugins\/code-snippets\/\" class=\"wp-pic-requires\" target=\"_blank\" title=\"WordPress.org Plugin Page\">\n\t\t\t\t\t\tWP 5.0+<em>Requires<\/em>\n\t\t\t\t\t<\/a>\n\t\t\t\t<\/div>\n\t\t\t<\/div>\n\t\t<\/div>\n\t<\/div>\n<\/div>\n<\/div><\/div><!-- .wp-pic-wrapper--><link rel='stylesheet' id='dashicons-css' href='https:\/\/themeisle.com\/blog\/wp-includes\/css\/dashicons.min.css?ver=6.8.5' type='text\/css' media='all' \/>\n<link rel='stylesheet' id='wppic-style-css' href='https:\/\/themeisle.com\/blog\/wp-content\/plugins\/wp-plugin-info-card\/dist\/wppic-styles.css?ver=6.1.1' type='text\/css' media='all' \/>\n<script type=\"text\/javascript\" src=\"https:\/\/themeisle.com\/blog\/wp-includes\/js\/jquery\/jquery.min.js?ver=3.7.1\" id=\"jquery-core-js\"><\/script>\n<script type=\"text\/javascript\" src=\"https:\/\/themeisle.com\/blog\/wp-includes\/js\/jquery\/jquery-migrate.min.js?ver=3.4.1\" id=\"jquery-migrate-js\"><\/script>\n<script type=\"text\/javascript\" id=\"wppic-script-js-extra\">\n\/* <![CDATA[ *\/\nvar wppicAjax = {\"ajaxurl\":\"https:\\\/\\\/themeisle.com\\\/blog\\\/wp-admin\\\/admin-ajax.php\"};\n\/* ]]> *\/\n<\/script>\n<script type=\"text\/javascript\" src=\"https:\/\/themeisle.com\/blog\/wp-content\/plugins\/wp-plugin-info-card\/assets\/js\/wppic-script.min.js?ver=6.1.1\" id=\"wppic-script-js\"><\/script>\n\n<p>It is a simple plugin that lets you add code snippets to your <em>functions.php<\/em> without any manual file editing. It treats code snippets as individual plugins of their own &#8211; you add the code and hit save &#8230; and the rest is handled by the Code Snippets plugin.<\/p>\n<p>Once you activate the plugin, you will find a Snippets menu right under &#8220;Plugins.&#8221; Head to <em>Snippets &raquo; Add New<\/em>:<\/p>\n<p><img data-opt-id=77472755  fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-large wp-image-2884\" src=\"https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:1024\/h:454\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippet-plugin-2.png\" alt=\"Code Snippets for WordPress\" width=\"810\" height=\"359\" style=\"-webkit-box-shadow: 0px 0px 8px 2px rgba(0,0,0,0.5);-moz-box-shadow: 0px 0px 8px 2px rgba(0,0,0,0.5);box-shadow: 0px 0px 8px 2px rgba(0,0,0,0.5);\" srcset=\"https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:1024\/h:454\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippet-plugin-2.png 1024w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:300\/h:133\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippet-plugin-2.png 300w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:768\/h:341\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippet-plugin-2.png 768w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:50\/h:22\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippet-plugin-2.png 50w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:480\/h:213\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippet-plugin-2.png 480w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:794\/h:352\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippet-plugin-2.png 794w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:1200\/h:532\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippet-plugin-2.png 1200w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:296\/h:131\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippet-plugin-2.png 296w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:390\/h:173\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippet-plugin-2.png 390w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:270\/h:120\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippet-plugin-2.png 270w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:1335\/h:592\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippet-plugin-2.png 1335w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:1335\/h:592\/q:mauto\/f:best\/dpr:2\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippet-plugin-2.png 2x\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<div class=\"su-row\">\n<div class=\"su-column su-column-size-1-2\"><div class=\"su-column-inner su-u-clearfix su-u-trim\">\n<p>Add a name for your snippet, paste the snippet in the code area, and then provide a description for your own reference. Once done, activate the snippet and you&#8217;re good to go! Even if you change the theme, the code snippet remains functional.<\/p>\n<\/div><\/div>\n<div class=\"su-column su-column-size-1-2\"><div class=\"su-column-inner su-u-clearfix su-u-trim\">\n\n\t\t<div class='ti-tweet-clear'><\/div>\n\t\t\t<div class='ti-tweet_wrapper'>\n\t\t    \t<div class='ti-tweet_text'>\n\t\t    \t\t<a href='https:\/\/twitter.com\/share?text=10+useful+%23code+%23snippets+for+%23WordPress+users+%F0%9F%96%A5%EF%B8%8F&via=themeisle&related=themeisle&url=https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/' target='_blank' rel='nofollow'>10 useful #code #snippets for #WordPress users \ud83d\udda5\ufe0f<\/a>\n\t\t    \t<\/div>\n\t\t    \t<div class='ti-tweet_sharebtn'>\n\t\t    \t<a href='https:\/\/twitter.com\/share?text=10+useful+%23code+%23snippets+for+%23WordPress+users+%F0%9F%96%A5%EF%B8%8F&via=themeisle&related=themeisle&url=https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/' target='_blank' rel='nofollow'>Click To Tweet \n\t\t    \t\t<span><\/span>\n\t\t    \t<\/a>\n\t\t    <\/div>\n\t\t<\/div>\n<\/div><\/div>\n<\/div>\n<p>This way, you can add and delete code snippets as if they were posts or pages without having to edit theme files at all.<\/p>\n<p><em><strong>So there you have it, useful code snippets for WordPress as well as a helpful plugin to add them all! Got a special code snippet for WordPress that you like? Share it in the comments below!<\/strong><\/em><\/p>\n<style>.ticss-d144f107 strong{font-weight: 700;\n    letter-spacing: -0.2px;\n    line-height: 1.2;\n    display: inline-block;}<\/style>\n\n\n<div class=\"wp-block-columns speed-guide has-white-color has-text-color has-background has-link-color wp-elements-2f81f6c5526477b5b4d52d1ca4513949 is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\" style=\"background-color:#4267cf\">\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:40%\">\n<figure class=\"wp-block-image size-medium\"><img data-opt-id=30701221  fetchpriority=\"high\" decoding=\"async\" width=\"300\" height=\"300\" src=\"https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:300\/h:300\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2025\/09\/e2ce20299a807336c68c2e029640adaa1.png\" alt=\"speed guide\" class=\"wp-image-113040\" srcset=\"https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:300\/h:300\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2025\/09\/e2ce20299a807336c68c2e029640adaa1.png 300w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:1024\/h:1024\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2025\/09\/e2ce20299a807336c68c2e029640adaa1.png 1024w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:150\/h:150\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2025\/09\/e2ce20299a807336c68c2e029640adaa1.png 150w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:768\/h:768\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2025\/09\/e2ce20299a807336c68c2e029640adaa1.png 768w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:50\/h:50\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2025\/09\/e2ce20299a807336c68c2e029640adaa1.png 50w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:240\/h:240\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2025\/09\/e2ce20299a807336c68c2e029640adaa1.png 240w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:397\/h:397\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2025\/09\/e2ce20299a807336c68c2e029640adaa1.png 397w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:600\/h:600\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2025\/09\/e2ce20299a807336c68c2e029640adaa1.png 600w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:148\/h:148\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2025\/09\/e2ce20299a807336c68c2e029640adaa1.png 148w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:195\/h:195\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2025\/09\/e2ce20299a807336c68c2e029640adaa1.png 195w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:135\/h:135\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2025\/09\/e2ce20299a807336c68c2e029640adaa1.png 135w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:1080\/h:1080\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2025\/09\/e2ce20299a807336c68c2e029640adaa1.png 1200w, https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:1080\/h:1080\/q:mauto\/f:best\/dpr:2\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2025\/09\/e2ce20299a807336c68c2e029640adaa1.png 2x\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p class=\"has-text-align-center ticss-58e79f2f\" style=\"font-size:14px\"><strong>FREE GUIDE<\/strong><\/p>\n\n\n\n<p class=\"ticss-d144f107\" style=\"font-size:25px\"><strong>4 Essential Steps to Speed Up Your&nbsp;WordPress Website<\/strong><\/p>\n\n\n\n<p class=\"ticss-3b627beb\">Follow the simple steps in our 4-part mini series and reduce your loading times by 50-80%.&nbsp;\ud83d\ude80<\/p>\n\n\n<p><div class=\"frm_forms  with_frm_style frm_style_themeisle\" id=\"frm_form_4_container\" data-token=\"6f00c030fd777e7369331211a5762e80\">\n<form enctype=\"multipart\/form-data\" method=\"post\" class=\"frm-show-form  frm_pro_form \" id=\"form_site-speed-guide-below-post\" data-token=\"6f00c030fd777e7369331211a5762e80\">\n<div class=\"frm_form_fields \">\n<fieldset>\n<legend class=\"frm_screen_reader\">Site Speed Guide - Below Post<\/legend>\r\n\r\n<div class=\"frm_fields_container\">\n<input type=\"hidden\" name=\"frm_action\" value=\"create\" \/>\n<input type=\"hidden\" name=\"form_id\" value=\"4\" \/>\n<input type=\"hidden\" name=\"frm_hide_fields_4\" id=\"frm_hide_fields_4\" value=\"\" \/>\n<input type=\"hidden\" name=\"form_key\" value=\"site-speed-guide-below-post\" \/>\n<input type=\"hidden\" name=\"item_meta[0]\" value=\"\" \/>\n<input type=\"hidden\" id=\"frm_submit_entry_4\" name=\"frm_submit_entry_4\" value=\"4776411368\" \/><input type=\"hidden\" name=\"_wp_http_referer\" value=\"\/blog\/wp-json\/wp\/v2\/posts\/2883\" \/><input type=\"hidden\" name=\"item_meta[18]\" id=\"field_6px6q2\" value=\"\/blog\/wp-json\/wp\/v2\/posts\/2883\"  data-frmval=\"\/blog\/wp-json\/wp\/v2\/posts\/2883\"   \/>\n<div id=\"frm_field_15_container\" class=\"frm_form_field form-field  frm_required_field frm_none_container\">\r\n\t<label for=\"field_6px6q\" id=\"field_6px6q_label\" class=\"frm_primary_label\">Your Email\r\n\t\t<span class=\"frm_required\" aria-hidden=\"true\">*<\/span>\r\n\t<\/label>\r\n\t<input type=\"email\" id=\"field_6px6q\" name=\"item_meta[15]\" value=\"\"  autocomplete=\"email\"  placeholder=\"your@email.com\" data-reqmsg=\"Your Email cannot be blank.\" aria-required=\"true\" data-invmsg=\"Your Email is invalid\" aria-invalid=\"false\"  \/>\r\n\t\r\n\t\r\n<\/div>\n<div id=\"frm_field_17_container\" class=\"frm_form_field form-field  frm_none_container vertical_radio\">\r\n\t<div  id=\"field_6px6q3_label\" class=\"frm_primary_label\">Subscribe to our newsletter\r\n\t\t<span class=\"frm_required\" aria-hidden=\"true\"><\/span>\r\n\t<\/div>\r\n\t<div class=\"frm_opt_container\" aria-labelledby=\"field_6px6q3_label\" role=\"group\">\t\t<div class=\"frm_checkbox\" id=\"frm_checkbox_17-0\">\t\t\t<label  for=\"field_6px6q3-0\">\n\t\t\t<input type=\"checkbox\" name=\"item_meta[17][]\" id=\"field_6px6q3-0\" value=\"true\"  data-invmsg=\"Subscribe to our newsletter is invalid\" aria-invalid=\"false\"   \/> Subscribe to our newsletter<\/label><\/div>\n<\/div>\r\n\t\r\n\t\r\n<\/div>\n<div id=\"frm_field_14_container\" class=\"frm_form_field form-field \">\r\n\t<div class=\"frm_submit frm_flex\">\r\n<button class=\"frm_button_submit frm_final_submit\" type=\"submit\"   formnovalidate=\"formnovalidate\">FREE ACCESS<\/button>\r\n\r\n\r\n\r\n<\/div>\r\n<\/div>\n\t<input type=\"hidden\" name=\"item_key\" value=\"\" \/>\n\t\t\t<div id=\"frm_field_24_container\">\n\t\t\t<label for=\"field_cjci0\" >\n\t\t\t\tIf you are human, leave this field blank.\t\t\t<\/label>\n\t\t\t<input  id=\"field_cjci0\" type=\"text\" class=\"frm_form_field form-field frm_verify\" name=\"item_meta[24]\" value=\"\"  \/>\n\t\t<\/div>\n\t\t<input name=\"frm_state\" type=\"hidden\" value=\"tGKtIG19U6wyYcew8uBttfTyNuPm6l1rDkePRbP2Y0qPSAm6AeCFrcPBJiK38Y1i\" \/><\/div>\n<\/fieldset>\n<\/div>\n\n<p style=\"display: none !important;\" class=\"akismet-fields-container\" data-prefix=\"ak_\"><label>&#916;<textarea name=\"ak_hp_textarea\" cols=\"45\" rows=\"8\" maxlength=\"100\"><\/textarea><\/label><input type=\"hidden\" id=\"ak_js_1\" name=\"ak_js\" value=\"20\"\/><script>document.getElementById( \"ak_js_1\" ).setAttribute( \"value\", ( new Date() ).getTime() );<\/script><\/p><\/form>\n<\/div>\n<\/p>\n<\/div>\n<\/div>\n\n","protected":false},"excerpt":{"rendered":"We know that plugins can be used to extend the functionality of WordPress. But what if you can do some smaller things in WordPress without installing them? Say, you dislike the admin bar at the top and wish to eliminate it? Yes, that can be accomplished by means of code snippets for WordPress.","protected":false},"author":10,"featured_media":68858,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_stopmodifiedupdate":false,"_modified_date":"","_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[272],"tags":[],"hashtags":[],"class_list":["post-2883","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress-tutorials"],"wppr_data":{"cwp_meta_box_check":"No"},"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.8 (Yoast SEO v26.1.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>10 Useful Code Snippets for WordPress Users<\/title>\n<meta name=\"description\" content=\"Code snippets for WordPress are used to do actions that might otherwise require a plugin. This article lists some useful code snippets for WordPress users.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"10 Useful Code Snippets for WordPress Users\" \/>\n<meta property=\"og:description\" content=\"Code snippets for WordPress are used to do actions that might otherwise require a plugin. This article lists some useful code snippets for WordPress users.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/\" \/>\n<meta property=\"og:site_name\" content=\"Themeisle Blog\" \/>\n<meta property=\"article:author\" content=\"http:\/\/facebook.com\/sufyanism\" \/>\n<meta property=\"article:published_time\" content=\"2016-09-29T13:00:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-18T09:33:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:auto\/h:auto\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippets-for-wordpress.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2180\" \/>\n\t<meta property=\"og:image:height\" content=\"1090\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Sufyan bin Uzayr\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sufyan bin Uzayr\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/\"},\"author\":{\"name\":\"Sufyan bin Uzayr\",\"@id\":\"https:\/\/themeisle.com\/blog\/#\/schema\/person\/14979b9ad14a961e63a8d4ab64402531\"},\"headline\":\"10 Useful Code Snippets for WordPress Users\",\"datePublished\":\"2016-09-29T13:00:07+00:00\",\"dateModified\":\"2023-08-18T09:33:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/\"},\"wordCount\":1374,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/themeisle.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:auto\/h:auto\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippets-for-wordpress.png\",\"articleSection\":[\"WordPress Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/\",\"url\":\"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/\",\"name\":\"10 Useful Code Snippets for WordPress Users\",\"isPartOf\":{\"@id\":\"https:\/\/themeisle.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:auto\/h:auto\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippets-for-wordpress.png\",\"datePublished\":\"2016-09-29T13:00:07+00:00\",\"dateModified\":\"2023-08-18T09:33:46+00:00\",\"description\":\"Code snippets for WordPress are used to do actions that might otherwise require a plugin. This article lists some useful code snippets for WordPress users.\",\"breadcrumb\":{\"@id\":\"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/#primaryimage\",\"url\":\"https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:auto\/h:auto\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippets-for-wordpress.png\",\"contentUrl\":\"https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:auto\/h:auto\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippets-for-wordpress.png\",\"width\":2180,\"height\":1090,\"caption\":\"Code Snippets for WordPress\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/themeisle.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"10 Useful Code Snippets for WordPress Users\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/themeisle.com\/blog\/#website\",\"url\":\"https:\/\/themeisle.com\/blog\/\",\"name\":\"Themeisle Blog\",\"description\":\"WordPress Tutorials and Reviews for Beginners and Advanced\",\"publisher\":{\"@id\":\"https:\/\/themeisle.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/themeisle.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/themeisle.com\/blog\/#organization\",\"name\":\"VertiStudio\",\"alternateName\":\"Vertigo Studio SA\",\"url\":\"https:\/\/themeisle.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/themeisle.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:auto\/h:auto\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2024\/02\/VertiStudio_logo1.png\",\"contentUrl\":\"https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:auto\/h:auto\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2024\/02\/VertiStudio_logo1.png\",\"width\":718,\"height\":156,\"caption\":\"VertiStudio\"},\"image\":{\"@id\":\"https:\/\/themeisle.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/themeisle.com\/blog\/#\/schema\/person\/14979b9ad14a961e63a8d4ab64402531\",\"name\":\"Sufyan bin Uzayr\",\"description\":\"Writer; web dev; published author; coffee-lover; learn more about my works at sufyanism.com.\",\"sameAs\":[\"http:\/\/sufyanism.com\",\"http:\/\/facebook.com\/sufyanism\"],\"url\":\"https:\/\/themeisle.com\/blog\/author\/sufyan\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"10 Useful Code Snippets for WordPress Users","description":"Code snippets for WordPress are used to do actions that might otherwise require a plugin. This article lists some useful code snippets for WordPress users.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/","og_locale":"en_US","og_type":"article","og_title":"10 Useful Code Snippets for WordPress Users","og_description":"Code snippets for WordPress are used to do actions that might otherwise require a plugin. This article lists some useful code snippets for WordPress users.","og_url":"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/","og_site_name":"Themeisle Blog","article_author":"http:\/\/facebook.com\/sufyanism","article_published_time":"2016-09-29T13:00:07+00:00","article_modified_time":"2023-08-18T09:33:46+00:00","og_image":[{"width":2180,"height":1090,"url":"https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:auto\/h:auto\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippets-for-wordpress.png","type":"image\/png"}],"author":"Sufyan bin Uzayr","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Sufyan bin Uzayr","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/#article","isPartOf":{"@id":"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/"},"author":{"name":"Sufyan bin Uzayr","@id":"https:\/\/themeisle.com\/blog\/#\/schema\/person\/14979b9ad14a961e63a8d4ab64402531"},"headline":"10 Useful Code Snippets for WordPress Users","datePublished":"2016-09-29T13:00:07+00:00","dateModified":"2023-08-18T09:33:46+00:00","mainEntityOfPage":{"@id":"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/"},"wordCount":1374,"commentCount":0,"publisher":{"@id":"https:\/\/themeisle.com\/blog\/#organization"},"image":{"@id":"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/#primaryimage"},"thumbnailUrl":"https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:auto\/h:auto\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippets-for-wordpress.png","articleSection":["WordPress Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/","url":"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/","name":"10 Useful Code Snippets for WordPress Users","isPartOf":{"@id":"https:\/\/themeisle.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/#primaryimage"},"image":{"@id":"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/#primaryimage"},"thumbnailUrl":"https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:auto\/h:auto\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippets-for-wordpress.png","datePublished":"2016-09-29T13:00:07+00:00","dateModified":"2023-08-18T09:33:46+00:00","description":"Code snippets for WordPress are used to do actions that might otherwise require a plugin. This article lists some useful code snippets for WordPress users.","breadcrumb":{"@id":"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/#primaryimage","url":"https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:auto\/h:auto\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippets-for-wordpress.png","contentUrl":"https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:auto\/h:auto\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2016\/09\/code-snippets-for-wordpress.png","width":2180,"height":1090,"caption":"Code Snippets for WordPress"},{"@type":"BreadcrumbList","@id":"https:\/\/themeisle.com\/blog\/code-snippets-for-wordpress\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/themeisle.com\/blog\/"},{"@type":"ListItem","position":2,"name":"10 Useful Code Snippets for WordPress Users"}]},{"@type":"WebSite","@id":"https:\/\/themeisle.com\/blog\/#website","url":"https:\/\/themeisle.com\/blog\/","name":"Themeisle Blog","description":"WordPress Tutorials and Reviews for Beginners and Advanced","publisher":{"@id":"https:\/\/themeisle.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/themeisle.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/themeisle.com\/blog\/#organization","name":"VertiStudio","alternateName":"Vertigo Studio SA","url":"https:\/\/themeisle.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/themeisle.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:auto\/h:auto\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2024\/02\/VertiStudio_logo1.png","contentUrl":"https:\/\/mllj2j8xvfl0.i.optimole.com\/cb:c5QE.37290\/w:auto\/h:auto\/q:mauto\/f:best\/https:\/\/themeisle.com\/blog\/wp-content\/uploads\/2024\/02\/VertiStudio_logo1.png","width":718,"height":156,"caption":"VertiStudio"},"image":{"@id":"https:\/\/themeisle.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/themeisle.com\/blog\/#\/schema\/person\/14979b9ad14a961e63a8d4ab64402531","name":"Sufyan bin Uzayr","description":"Writer; web dev; published author; coffee-lover; learn more about my works at sufyanism.com.","sameAs":["http:\/\/sufyanism.com","http:\/\/facebook.com\/sufyanism"],"url":"https:\/\/themeisle.com\/blog\/author\/sufyan\/"}]}},"_links":{"self":[{"href":"https:\/\/themeisle.com\/blog\/wp-json\/wp\/v2\/posts\/2883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themeisle.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themeisle.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themeisle.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/themeisle.com\/blog\/wp-json\/wp\/v2\/comments?post=2883"}],"version-history":[{"count":15,"href":"https:\/\/themeisle.com\/blog\/wp-json\/wp\/v2\/posts\/2883\/revisions"}],"predecessor-version":[{"id":79965,"href":"https:\/\/themeisle.com\/blog\/wp-json\/wp\/v2\/posts\/2883\/revisions\/79965"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themeisle.com\/blog\/wp-json\/wp\/v2\/media\/68858"}],"wp:attachment":[{"href":"https:\/\/themeisle.com\/blog\/wp-json\/wp\/v2\/media?parent=2883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themeisle.com\/blog\/wp-json\/wp\/v2\/categories?post=2883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themeisle.com\/blog\/wp-json\/wp\/v2\/tags?post=2883"},{"taxonomy":"hashtags","embeddable":true,"href":"https:\/\/themeisle.com\/blog\/wp-json\/wp\/v2\/hashtags?post=2883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}