Trouble
I was also in same trouble! But I managed to solve the problem today.It may not perfect answer but it'll be useful help,I guess.
It's sure as you said, Wordpress automatically change the ID to URL.
(e.g.
clip-path: url('#clip-this');
→ https://xxxx/wp-content/themes/my-theme/index.html#clip-this
)
So unless you use plain html without Wordpress,you can't get correct clip-path itself with using the ID.
Answer
Anyway, ID is not available.
So I came to think Using ID is not correct solution,but
"USING DIRECT PATH-DATA IN CSS" would be solution.
Then I finally get clipped image in wordpress!(and more, using @keyframes rule to change path-data, I could get animated clipped image by svg too!)
How to...
open SVG Code in text editor, find d="",and copy value (in quotes).
e.g.
d='M60.5,-15.7C67.8,2.8,55.7,31.4,36.8,43.5C17.9,55.6,-7.9,51,-24.2,38C-40.5,25.1,-47.3,3.7,-41.7,-12.5C-36.1,-28.7,-18,-39.8,4.3,-41.2C26.6,-42.6,53.2,-34.3,60.5,-15.7Z'
paste to clip-path: path("here")
instead of clip-path: url("#ID")
.
e.g.
clip-path:path('M60.5,-15.7C67.8,2.8,55.7,31.4,36.8,43.5C17.9,55.6,-7.9,51,-24.2,38C-40.5,25.1,-47.3,3.7,-41.7,-12.5C-36.1,-28.7,-18,-39.8,4.3,-41.2C26.6,-42.6,53.2,-34.3,60.5,-15.7Z')
Attention! Not url()
but path()
value is used.
Ploberbly, you can get clipped image at this point.
In addition
Moreover, when you want to get responsive aspect ratio about mask image, you may not use <img>
, but use <image />
in <svg>
.
eg.
in HTML
instead of <img src="path/to/file.jpg">
...
<svg viewbox="0 0 200 200">
<image xlink:href="path/to/file.jpg" preserveaspectratio="XmidYMid slice" />
</svg>
-When you write this on cutom-html-widget-editor in Wordpress theme customizer-
'viewBox' and 'preserveAspectRatio' attributes prefer to be wrote in lower case
like 'viewbox' 'preserveaspectratio' because this Wordpress editor says it may be error or you have to fix it.
-<svg>
viewbox's value should be set as same as viewbox’s value of clip shape SVG-
When you want to get right-size of image in any devices, you should set same value in viewbox between clipping <svg>
and clipped <svg>
(including <image />
)
For example,clipping svg having value <svg viewBox=“0 0 500 300”>
,you should write same to clipped svg <svg viewbox=“0 0 500 300”><image …
in CSS
image{
clip-path:path("M123.456,789.........z");
width:100%;
height:100%;
and so on...
}
Anyway,in Wordpress
clip-path:url("#id")
is not working,
clip-path:path("path-data")
is working!