admin管理员组文章数量:1316363
Can anyone please help me? please see the screenshot. it is a JS file. here I want to get permalink of my custom posts. But I don't understand how get permalink into a JS fils. So, please help to out this solution.
Can anyone please help me? please see the screenshot. it is a JS file. here I want to get permalink of my custom posts. But I don't understand how get permalink into a JS fils. So, please help to out this solution.
Share Improve this question edited Nov 28, 2016 at 8:08 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Nov 23, 2016 at 4:18 Shakib HasanShakib Hasan 11 bronze badge 01 Answer
Reset to default 1To get a permalink you need to use get_permalink()
. Just pass the ID of the post or leave it blank to get the current page in the Loop.
wp_localize_script ()
will render PHP variables on the page that are consumable by JS through a global object that you define.
PHP
// Register the script
wp_register_script( 'some_handle', 'path/to/myscript.js' );
// Localize the script with new data
$translation_array = array(
'some_string' => __( 'Some string to translate', 'plugin-domain' ),
'a_value' => '10'
);
wp_localize_script( 'some_handle', 'object_name', $translation_array );
// Enqueued script with localized data.
wp_enqueue_script( 'some_handle' );
JS
<script>
// alerts 'Some string to translate'
alert( object_name.some_string);
</script>
The REST-API is also always available for you to extend how you see fit: http://v2.wp-api/extending/adding/
本文标签: jqueryhow to get permalink
版权声明:本文标题:jquery - how to get permalink 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742003489a2411489.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论