Learn how to use the Selector option to enable image sharing only for specific pages.
Share This Image plugin gives you the great option to make shareable any image on your site ( and even not only images ).
All magic comes from the Selector option from the plugin settings page. By default it is set to img
.
This means that all images on your site will be available for sharing ( of course, if their sizes are fit to those ones that are specified inside Minimal width
and Minimal height
options of the plugin settings page ).
But what to do if we need to enable image sharing only for specific pages? In this case we will need to customize an already known to us Selector option.
There are different cases depending on what pages we need sharing to be active - single unique page, archive pages, single post page, etc. Below we will consider examples of such page types.
If it is a single unique page that is created via Page -> Add New admin page then you can just use the selector option with this page ID to limit image sharing for this page only. For example, we have a page with ID 123
. Then just set the Selector option value to
.page-id-123 img
Also you can specify several such pages by using commas. For example use
.page-id-123 img, .page-id-456 img
to enable image sharing only for pages with IDs 123
and 456
.
For example, you want to share the images inside all archive pages like categories
, tags
, date
, author
, etc. To archive this just use selector
.archive img
To enable image sharing on category archive pages just use selector
.archive.category img
If you want to be more specific and enable sharing only on certain category archive pages then use selector
.category-{ID} img
where {ID}
- category term ID.
For example, if we want to enable sharing only for category term Featured
that has ID 345
than we just need to use selector
.category-345 img
Or it is also possible to use category slug like
.category-featured img
If you are using any custom taxonomy and it has its own archive page that you can limit the plugin to work only on those archive pages. Just use selector
.tax-{taxonomy_slug} img'
For example for custom taxonomy product_cat
selector will looks like
.tax-product_cat img
To limit image sharing only for single blog posts simply use selector
.single-post img
If it is needed to enable image sharing only to specific blog post use selector like
.single-post.postid-{ID} img
where {ID}
- your blog post ID.
If you are using any custom post type and want to use image sharing only on that posts than use selector
.single-{post_type} img
where {post_type}
- your custom post type slug.
If it is needed to enable image sharing only to specific post use selector
.single-{post_type}.postid-{ID} img
where {ID}
- your post ID.
In the examples above we use selectors to enable image sharing on some pages and exclude on all others. But the selector option can be used and vice versa - exclude image sharing on specific pages and enable sharing on all other.
To use such rules you need to use a special css selector :not
.
For example, we need to exclude images sharing for pages with ID 123
and enable it on all other pages. So just use selector
body:not(.page-id-123) img
So comes and for all other selector types. For example, to disable image sharing on archive pages and enable on all other please use
body:not(.archive) img