I’m trying to get WordPress website title using javascript and WP API plugin
I didn’t find any example on how to get the site’s name but I found the variable name under the entities section in the developer guide
function _updateTitle(documentTitle) {
document.querySelector('title').innerHTML =
documentTitle + ' | '+ $http.get('wp-json/name');
}
The output string of $http.get('wp-json/name')
is [object Object]
Does anyone know how to use fix this?
You didn’t get enough context. What’s
$http
? What happens when you go to wp-json/name directly in your browser? Here’s what I see:Here’s a simple example to get you the title:
See more elegant solution here https://wordpress.stackexchange.com/a/314767/94636
response will not contain extra data like:
authentication: []
namespaces: ["oembed/1.0", "akismet/v1", "acf/v3", "wp/v2"]
routes: {/: {namespace: "", methods: ["GET"],â¦},â¦}
timezone_string: ""
...
_links: {help: [{href: "http://v2.wp-api.org/"}]}