I have a valid page name that I need to resolve to a page title. Example:
Main.TargetPage
(:title Page One:)
I am the page of which the title needs to be got.
Main.CurrentPage
(:title Example Page:)
I am the page that the PHP script is being run from.
How can I get the title of Main.TargetPage from Main.CurrentPage?
You can get the title of a page with this function call:
$PageTitle = PageVar(ResolvePageName('Main/TargetPage'), '$Title');
You can get the other's page title by command {Main.TargetPage$Title}, see official docs:
Related
I'm new to wordpress and I'm following a tutorial right now but I don't understand wordpresses behaviour. I'm trying to change the title of a sidebar which lists the parentpage and it's childpages, this works fine but I don't understand why $parentID = wp_get_post_parent_id(get_the_ID()); echo get_permalink($parentID); works even on the parent page, I echoed the result on the parent page and it returns 0 since the parent page doesnt have a parent, so why does this still work? Why does get_permalink(0); get me to the parent page if I press the button?
get_permalink()is the function that gives you the link to the post/page inside the loop you are currently. Since you are not having parent page for the current page get_permalink is not able to get you to the parent page as nothing exist so in this case it will rediret you to the same page.
I have a photo gallery page that is using a single page in Wordpress.
The gallery display is dynamic, and relies on a URL parameter. The parameter itself is an integer of the relating wordpress page ID. (as that's the page it's about).
Here is an example of a gallery URL:
http://www.bellavou.co.uk/gallery/?pid=238
For SEO purposes, I'm trying to get away from every possible Gallery URL combination to have the page title 'Gallery', as is set in the Wordpress page settings.
I've been trying this, which has been mentioned a few times:
function assignPageTitle(){
return "Title goes here";
}
add_filter('wp_title', 'assignPageTitle');
But as I'm also using Yoast SEO plugin, I think this is over-writing it (even though I uncheck 'Force title rewrite', and keep the page title field blank). Not sure why the above function doesn't seem to work.
Within the gallery page, I'm able to show the h1 title properly, passing PHP Variables into the code, but I want to do the same to the page title, but in a way that can be done directly on the page template.
Why is it that whenever I post a question, I seem to find the answer very soon afterwards?
I read a post saying that it helps to put a wp_title function before the wp_header call, which is what I tried, and that seems to work fine.
I can edit the page title just for an individual page using the PHP page template, and using this:
$procedure = isset($_GET['pid']) ? $_GET['pid'] : '';
add_filter( 'wp_title', 'wp_title_gallery', 100 );
function wp_title_gallery($title) {
global $procedure;
if(!$procedure) {
$title = the_title();
} else {
$title = the_title(get_the_title($procedure).' ');
}
return $title;
}
get_header();
$procedure gets the URL parameter, and then the function takes that ID, and gets the associated page from it, and then prints the title of the page, into the page title hook. Lastly, the WP header is called.
(Just incase anyone comes here looking for a solution)
I set my title of the page like this in the blade view template:
#section('title', 'Example.com - Welcome to Example.com for all your needs')
This is working well. Now I want to know how can I access/print the current page title in the body part?
I mean for getting the current URL, we can use Request::url(). Is there a way that I can get the current page title?
I don't know of a way to do this in Laravel, but this is easily accomplished in Javascript/JQuery:
$(document).ready(function(){
console.log($("title").text());
});
Will print the title of the current page to the console. You can assign this value to an element by targeting it's id $("#id_of_element") or class $(".class_of_elemnt") and setting the text to the title's text:
$("#id_of_element").text($("title").text());
Hope that helps!
I think it's not a good idea to set the page title with hard code in layout file.
one of the best ways is to have a default page title in layout and override it in every view page.
just like below :
layout title :: {{ isset($title) ? $title : 'page title' }}
You can print your page title using
#yield('title)
wherever you want.
I have a php site template and i want to create hyperlinks to the homepage on the internal pages. I tried this code which works in wordpress but doesn't work on my template: anchor text
What alternative code i can use to replace <?php echo home_url(); ?>, so it will work on my php template?
edit:
This worked Homepage! but i have another problem. In my php template the most recent pages are displayed on the homepage in a same way as a wordpress site. For the inner pages I am using this code page title to create hyperlinks for the page title similiar to the blog posts in wordpress. The problem is that the pages on the homepage are linking to the homepage not to the page url. For exmple, page with title Blue Widget has this page url domain.com/blue-widget, but when the page is displayed on the home page the page title is linking to domain.com.
How can i make the page title that are displayed on the homepage to link to they corresponding page url and not to the homepage. The same way blog posts that are dispalayed on the homepage of wordpress site are linking to they blog post pages.
Homepage link is just (when you have one domain):
Homepage!
Create a constant, somewhere in a central place like a config file. Then use it throughout the script.
define ('SITELINK', 'http://www.stackoverflow.com');
And in your template:
Go to home!
Or you can wrap it into a function:
<?php
function home_url(){
return SITELINK;
}
?>
Go to home!
Go to about page!
For referring only homepage:
In php
echo 'anchor text';
In Html
anchor text
Use "/" to redirect to home page from any other page.
The problem with $_SERVER['SERVER_NAME']; is it can be unreliable on some instances such as subdomains, etc...
Here is WordPress' Reference Manual: http://codex.wordpress.org/Function_Reference/network_home_url
In WordPress you can use:
$url = network_home_url();
echo $url;
So for you example it would be:
anchor text
Hope that helped.
<?php
function home_url(){
?>Go Home<?php
}
home_url();
try to use $_SERVER['SERVER_NAME']; to get the home URL
Home
Any way to get the page title in magento...I Have a script live person..on this I need the current page title ..So can anybodey tell me how i get the current page title?
use this code
$this->getLayout()->getBlock('head')->getTitle();
you can use this code in your phtml file
To get the title without the Prefix (site name):
<?php echo str_replace(Mage::getStoreConfig('design/head/title_prefix'), '', $this->getLayout()->getBlock('head')->getTitle()); ?>