Hyperlink Predetermined Text on Every Post
-
mikeshowlingdeals.com
While `function add_before_content($content) {
return ‘<a href=”www.mikeshowlingdeals.com/privacy-policy/”>The links in the post below may be affiliate links.</a>
‘.$content;
}
add_filter(‘the_content’, add_before_content);`
shows the same text on every post, hyperlinked text only appears after clicking on a post title to go directly to the post. How do I get the predetermined text to be hyperlinked on all pages?Also, how do I do a line break on all pages? Just like the hyperlink, the line break only appears after clicking on a post title.
I was told on the WordPress support forum that my “theme is using the_excerpt() in the index and archive pages;” and to ask here on how to change that. Thanks for any help.
-
Yes, this theme utilizes the excerpt display in the blog, archive and search pages. So, from the above code which you have provided, seems to be hooked in the
the_contentfilter. Since it is hooked on that filter, it will be displayed in the content when it is opened up. So, to display that in the archive, blog and search pages, you need to simply replace the abovethe_contentfilter tothe_excerptfilter and check. What I meant to say here is, you need to change:
add_filter('the_content', 'add_before_content')
to this one:
add_filter('the_excerpt', 'add_before_content')And for the line break in those pages too, you need to manually edit those post and then enable the Excerpt option, which is usually under the Screen Options in the top right corner. After you check on the checkbox option of Excerpt, you will get the Excerpt option just below the post editor. Now, write anything there as you want to display the texts in the front-end.
Thanks.
Regards.
Bishal NapitThanks for the reply. Replacing add_filter(‘the_content’, ‘add_before_content’) to add_filter(‘the_excerpt’, ‘add_before_content’) causes the website to go down though, and I have to edit functions.php and put back the default code.
Have you changed the code properly and closed the php codes in there properly? I am asking it since in my local environment, I have not got any of the issue on it and so, I have suggested it.
Thanks.
Regards.
Bishal NapitSorry, I am new to all this. Does the code have to be something else than this? `function add_before_content($content) {
return ‘<a href=”www.mikeshowlingdeals.com/privacy-policy/”>The links in the post below may be affiliate links.</a>
‘.$content;
}
add_filter(‘the_excerpt’, ‘add_before_content’);`Thanks.
The above provided code is the correct one. So, can you tell which error are you getting using that code in your site? Also, your link is linking to the page not found, ie, your site followed by the link added in that filter there. So, can you try this code and check:-
function add_before_content($content) { return '<a href="http://www.mikeshowlingdeals.com/privacy-policy/">The links in the post below may be affiliate links.</a> '.$content; } add_filter('the_excerpt', 'add_before_content');Thanks.
Regards.
Bishal NapitThanks a lot; that code worked. http://www.mikeshowlingdeals.com/privacy-policy/? It works for me.
Oops, not resolved. I just noticed the hyperlink only appears on a page and not within a post. It doesn’t show up on the post when clicking on the title.
So, it seems that you like to add that link to the content page too. So, for this, you need to add that function to the the_content too, ie, what I meant to say is you need to add this code just below that above provided code:
add_filter('the_content', 'add_before_content');
So, the final code to be added in your child theme’s functions.php file will be:function add_before_content($content) { return '<a href="http://mikeshowlingdeals.com/privacy-policy/">The links in the post below may be affiliate links.</a> '.$content; } add_filter('the_excerpt', 'add_before_content'); add_filter('the_content', 'add_before_content');If you like this theme and appreciate the effort in making this theme, they you can help via rating this theme.
Thanks.
Regards.
Bishal NapitThat fixes the content page part, but now there’s two “The links in the post below may be affiliate links.” on the blog pages…one hyperlinked and one as text.
You can solve that issue via adding the Custom Excerpt for the post, which is already described above about how to do it in your site.
Thanks.
Regards.
Bishal NapitIs add_filter(‘the_excerpt’, ‘add_before_content’);
already a custom excerpt? Because it is added. I left a theme review yesterday. Thanks for all the help.The filter allows you to add the content in all of the posts, in the blog, archive and search pages. And it is also not the custom excerpt too.
Adding the custom excerpt is already described above. But if you get confusion on adding the manual excerpt for the post, then, you can follow this link to add those: http://www.wpbeginner.com/plugins/how-to-customize-wordpress-excerpts-no-coding-required/
Thanks.
Regards.
Bishal NapitOh, okay. I was hoping for the content to show up automatically after creating a post without me having to do anything. I have only found a plugin that still makes me have to click at the end of the text and press enter on each post. I just wanted to save time and not have to do that for every post. I’ll figure something out. Thanks for all the help.
It looks like you are trying to display the content too in the archive, search and blog pages, right? If yes, then, you can duplicate the file ‘template-parts/content.php’ in your child theme. In this file you will find the below code:
<div class="entry-content"> <?php if (is_single()) : the_content(); else : if (is_sticky()) : // displaying full content for the sticky post the_content(sprintf( /* translators: %s: Name of current post. */ wp_kses('<button type="button" class="btn btn-primary continue-more-link">' . __('Read More <i class="fa fa-arrow-circle-o-right"></i>', 'creative-blog') . '</button> %s', array('span' => array('class' => array()), 'i' => array('class' => array()), 'button' => array('class' => array(), 'type' => array()))), the_title('<span class="screen-reader-text">', '</span>', false) )); else : the_excerpt(); // displaying excerpt for the archive pages endif; endif; ?> <?php wp_link_pages(array( 'before' => '<div class="page-links">' . esc_html__('Pages:', 'creative-blog'), 'after' => '</div>', )); ?> </div><!-- .entry-content -->Now, you just need to change the above code with the below one and check:
<div class="entry-content"> <?php the_content(sprintf( /* translators: %s: Name of current post. */ wp_kses('<button type="button" class="btn btn-primary continue-more-link">' . __('Read More <i class="fa fa-arrow-circle-o-right"></i>', 'creative-blog') . '</button> %s', array('span' => array('class' => array()), 'i' => array('class' => array()), 'button' => array('class' => array(), 'type' => array()))), the_title('<span class="screen-reader-text">', '</span>', false) )); ?> <?php wp_link_pages(array( 'before' => '<div class="page-links">' . esc_html__('Pages:', 'creative-blog'), 'after' => '</div>', )); ?> </div><!-- .entry-content -->Thanks.
Regards.
Bishal NapitThanks so much. That solved it! Sorry if I was not explaining things clearly before.
The topic ‘Hyperlink Predetermined Text on Every Post’ is closed to new replies.
