我正在编写一个简单的 chrome 扩展来查找页面正在运行的 wordpress 主题的名称。解析“wp-content/theme”然后返回主题后的下一个单词是最容易的吗?
例子:
查找 - wp-content/theme/
<link rel="stylesheet" id="pagelines-pro-css" href="http://example.com/wp- content/themes/platformpro/"
返回文本 - Plateforpro
我正在编写一个简单的 chrome 扩展来查找页面正在运行的 wordpress 主题的名称。解析“wp-content/theme”然后返回主题后的下一个单词是最容易的吗?
例子:
查找 - wp-content/theme/
<link rel="stylesheet" id="pagelines-pro-css" href="http://example.com/wp- content/themes/platformpro/"
返回文本 - Plateforpro
你可以得到 jQuery 的链接并检查它是否是 wordpress 主题的链接,然后得到最后一部分,如下所示:
$('link').each(function() {
var href = $(this).attr('href');
if (href.indexOf('wp-content/themes') != -1) {
if (href.lastIndexOf('/') == href.length - 1) {
href = href.substring(0, length- 2);
}
var theme = href.substring(href.lastIndexOf(/), href.length - 1);
}
}
除了主题可以在主题的子文件夹中。你要小心那个。