A Complete Guide to Snippet Locations

Snippet locations are places on your website where you can have WPCode automatically execute your snippets.

Some locations are only available to PHP snippets as they are more generic and useful for running snippets earlier (before the output to the browser starts).

The currently available locations are:

  • Run Everywhere (PHP Only)

    • Run Everywhere – run PHP snippets everywhere (uses the plugins_loaded hook), this is most useful when you want to add hooks to the init action, for example, like when registering a custom post type.
    • Frontend Only – this location uses the same plugins_loaded hook mentioned above but limits the execution to the site frontend, this is useful when you want to add hooks that are not supposed to run in the admin, one common example would be a snippet that changes a query.
    • Admin Only – this is meant to be used for snippets that really don’t need to be ran on the frontend of the site, for example if you want to add a script using the admin_enqueue_scripts action, you can use this location to avoid running that code on the frontend as it would not do anything anyway.
  • Site Wide

    • Site Wide Header – this location executes snippets in the <head> of the page and is most commonly used for adding scrips to the page. You can alternatively use the Headers & Footers option but using this snippet one you have more control over where the snippet is loaded using conditional logic.
    • Site Wide Body – this location attempts to execute snippets after the opening body tag using the wp_body_open action. Please note that some themes may not be using this action.
    • Site Wide Footer – similarly to the header and body above, it will execute snippets in the footer of pages before the closing </body> tag.
  • Page, Post, Custom Post Type

    • Insert Before Post – like all the locations in this category, this location will only execute snippets on single pages of posts, pages or any other post type. This location executes snippets before the post content.
    • Insert After Post – similar to the previous location, only this time after the post.
    • Insert Before Content – this location will attempt to execute snippets before the post content (after the title).
    • Insert After Content – same as the one above, only it will execute the snippets after the post content.
    • Insert Before Paragraph – this location allows you to insert snippets before a specific paragraph, a new field becomes available when choosing this option where you can input the paragraph number where you want the snippet to be added.
    • Insert After Paragraph – similar to the one above it but it will execute snippets after the paragraph indicated by the number field.
  • Categories, Archives, Tags, Taxonomies

    • Insert Before Excerpt – on pages with lists of posts like the one mentioned in the name of the category this location will execute snippets before the post exceprt (if it is visible)
    • Insert After Excerpt – similar to the one above only it will add snippets after the except.
    • Between Posts – this location will execute snippets between all the posts in a list.
    • Before Post – this location will execute snippets before a specific post number – indicated in the field that shows up when selecting it.
    • After Post – similar to the one above only it will execute snippets after the indicated post.

There you have it! Now you know what each location in the WPCode plugin is used for and you can have better control over the way you display and execute snippets on your site.

For even more refinement and control you can always supplement the locations described above using the Smart Conditional Logic rules.