Affichage des articles dont le libellé est Title. Afficher tous les articles
Affichage des articles dont le libellé est Title. Afficher tous les articles

samedi 12 novembre 2016

How to Split Post or Page Title in WordPress



Do you want to split a WordPress post or page title into a new line? By default, your post title is just a single heading, and you cannot break it into a new line. In this article, we will show you how to split post or page title in WordPress.


Split post or page title in line breaks


Difference between Split Title and a Subtitle in WordPress


Splitting a post or page title allows you to break the title into a new line without changing formatting or style.


A long post title


On the other hand, a subtitle allows you to add two different headings for your WordPress post or page.


A WordPress page with a title and subtitle


See our tutorial on how to add subtitle for posts and pages in WordPress for detailed instructions.


Having said that, let’t see how to split post or page title in WordPress without writing any code.


Split Post or Page Title in WordPress


First thing you need to do is install and activate the Page Title Splitter plugin. For more details, see our step by step guide on how to install a WordPress plugin.


Upon activation, you need to edit a post or page where you want to split the title. On the post editor screen, you need to click on the little button below the title field.


Split button


Clicking on the button will add a pointer below the title field. You will need to click on the pointer to select it.


After that you can move the cursor inside text field to the point where you want to split the title.


Title splitter marker


You can also add multiple split points to break your title into more lines. Just click on the icon and then move the marker by selecting and putting the cursor at the right place.


Multiple splits


You can also delete a marker. Just click on a marker to select it, and you will notice that the title splitter button will turn into a close button. Clicking on it will remove the title splitting marker from your post title.


Once you are finished adding and adjusting the split marker, you can just save or publish your post.


You can now visit the post or page to see the split post title on your website.


A post title splitted into line breaks


We hope this article helped you learn how to split post or page title in WordPress. You may also want to see our guide on how to add a reading progress bar with your WordPress posts.


If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.


The post How to Split Post or Page Title in WordPress appeared first on WPBeginner.







How to Link to External Links from the Post Title in WordPress



Do you want to add an external link as post title in WordPress? Sometimes you may just want to share a link with your users. Instead of sending them to a post, you may want the post title to link to the other website. In this article, we will show you how to link to external links from the post title in WordPress.


Adding External Link to WordPress Post Title


Method 1: Linking Post Title to an External Link in WordPress using Plugin


This method is easier and is recommended for beginners.


First thing you need to do is install and activate the Page Links To plugin. For more details, see our step by step guide on how to install a WordPress plugin.


Upon activation, simply create a new post or edit an existing one. You will notice the new ‘Page Links To’ meta box below the post editor.


Adding a custom URL in page links to


Click on ‘A custom URL’ to add the link you want to add to post title. Now you can save or publish your post.


That’s all. The post title will now link to the custom URL you provided.


It is not necessary to use it for external links only. You can also use it to send users to different posts and pages on your WordPress site.


Method 2: Add External Link to Post Title Using Code


This method requires you to add code to your WordPress site. You can use this method if you are comfortable with pasting snippets from web into WordPress.


Simply add this code to your theme’s functions.php file or a site-specific plugin.



function print_post_title() {
global $post;
$thePostID = $post->ID;
$post_id = get_post($thePostID);
$title = $post_id->post_title;
$perm = get_permalink($post_id);
$post_keys = array(); $post_val = array();
$post_keys = get_post_custom_keys($thePostID);

if (!empty($post_keys)) {
foreach ($post_keys as $pkey) {
if ($pkey=='external_url') {
$post_val = get_post_custom_values($pkey);
}
}
if (empty($post_val)) {
$link = $perm;
} else {
$link = $post_val[0];
}
} else {
$link = $perm;
}
echo '<h2><a href="'.$link.'" rel="bookmark" title="'.$title.'">'.$title.'</a></h2>';
}

This code looks simply looks for a custom field containing your custom URL. If the post has the custom field, then it outputs the post title linked to your URL.


The next step is to replace your theme’s default display of post title with this function. You will find it in archives.php, content.php, category.php and other templates. It would look something like this:



<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>

You need to replace it with this code:



<?php print_post_title() ?>

The code part is over, now you need to add the external URL to the post. Simply edit the post or create a new one. On the post editor page, look for the custom fields meta box.


If you cannot see the custom fields meta box, then you need to click Screen Options in the top right corner of the screen. This will bring down a menu where you need to check the box next to ‘Custom Fields’.


Show custom fields meta box on the post edit screen in WordPress


You will find the custom fields meta box below the post editor.


Click on ‘Enter New’ and then enter external_url in the ‘Name’ field and the URL you want to add to post title in the ‘Value’ field.


Adding new custom key


You can now save or publish your post. That’s all, your post title will now be linked to the URL you added in the custom field.


Next time you need to add a link, you just need to select the external_url custom field from the drop down menu and enter your external link in the value field.


We hope this article helped you learn how to link to external links from the post title in WordPress. You may also want to see our guide on how to add an external link icon on your WordPress Site.


If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.


The post How to Link to External Links from the Post Title in WordPress appeared first on WPBeginner.