I want to make the [...] displayed in posts page as hyperlink to that particular posts. I get to know that this is from get_the_excerpt().
How can this be achieved? Thanks in advance.
copy this function to your functions.php
function new_excerpt_more($more) {
global $post;
return '<span class="readmore"><a class="moretag" href="'. get_permalink($post->ID) . '"> Read more..</a></span>';
}
add_filter('excerpt_more', 'new_excerpt_more');
Related
I'm trying to insert a button to show at the end of each post on Wordpress in which the link it goes to is defined by a setup using the custom fields plugin. When creating each post, I am able to select the link I wish to display.
Here is the code I have which I know is wrong but I was hoping someone could help here.
function wpb_after_post_content($content){
if (is_single()) {
$content .= 'Contact Franchise →';
}
return $content;
}
add_filter( "the_content", "wpb_after_post_content" );
I assume $franchise_profile_url is a variable and you should concatenate it in the string like this
$content .= 'Contact Franchise →';
function afterContent($content) {
if(!is_feed() && !is_home()) {
$content.= "<div class='footNote'>";
$content.= "<h4>Click the below button if you like it:</h4>";
$content.= "<p><a href='#'>LIKE</a></p>";
$content.= "</div>";
}
return $content;
}
add_filter ('the_content', 'afterContent');
Use the above function. It will help you to achieve what you need.
Thanks for the help here, however, that code simply links back to the post itself and isn't pulling in the URL as set on the post using custom fields. This is the code I had set up before which was working on a default post setup but now I wish to use an alternative method in the functions.php file
<?php if( get_field('franchise_profile_url') ): ?>
Contact Franchise →
<?php endif; ?>
I made a simple WordPress plugin which highlights text.
add_shortcode('close-span', 'highlighter_closing_span_shortcode');
function highlighter_closing_span_shortcode($atts) {
return '</span>';
}
It's the closing shortcode part of the plugin. In this case, users must type "[close-span]". I want to change it to "[/span]". How can I modify the code above?
You can use the $content parameter of the shortcode to allow users to put copy between tags:
add_shortcode( 'span', 'my_span_shortcode' );
function my_span_shortcode( $atts, $content = null ){
return '<span class="highlighted">' . $content . '</span>';
}
You would use the shortcode like this:
[span]This will be highlighted[/span]
and that would result in:
<span class="highlighted">This will be highlighted</span>
Hi #Peter (would comment if I could) this may go without saying but have you tried
add_shortcode('/span', 'highlighter_closing_span_shortcode');
function highlighter_closing_span_shortcode($atts) {
return '</span>';
}
I have reviewed the other posts similar to my questions but I must be missing a something.
I have added excerpts to my page like so:
[title size="2"]LATEST ARTICLES[/title]
[recent_posts columns="4" number_posts="12" cat_id="" thumbnail="yes" excerpt="yes" title="yes"] [/recent_posts]
I am trying to do two things
set the length of the excerpt
make it link to the article (not necessarily a read more link the dots are fine)
I have tried to add the excerpt manually to the excerpt area (screen options) for the page but that is not overwritting what Wordpress is pulling from.
in my function.php file I am using
add_filter('the_excerpt', 'do_shortcode');
which works, but when I tried to add additional code below it does not do anything. Do I need to modify anothe rphp file to get this to register?
`enter code here`function new_excerpt_more($more) {
return '' . ' read on ..' . '';
}
add_filter('excerpt_more', 'new_excerpt_more');
function new_excerpt_length($length) {
return 46;
}
add_filter('excerpt_length', 'new_excerpt_length');
I have achieved your desired result w/ the following code (from the codex):
function custom_excerpt_length( $length ) {
return 46;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
function new_excerpt_more( $more ) {
return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">' . __('Read More', 'your-text-domain') . '</a>';
}
add_filter( 'excerpt_more', 'new_excerpt_more' );
Is there a Wordpress function for grabbing the page attributes? I need to be able to check which templates are being used on which pages.
I have tried the get_post and get_pages but neither one outputs the page attributes.
Thanks in advance!
solution:
$ids= get_all_page_ids();
foreach ($ids as $id){
$meta = get_metadata('post', $id);
//var_dump($meta);
$template = $meta['_wp_page_template'][0];
echo $template;
echo "<br>";
}
Try using get_all_metadata. That will fetch all the meta records for a given object.
<?php
$post_id = 123;
$meta = get_metadata('post', $post_id);
echo $meta['my_custom_field_key'];
The docs are a good place to look: Function Reference « WordPress Codex
i.e.: Function Reference/get page template which
Displays the filename of the page template used to render a Page
(printed within an HTML comment, in this example) :
<?php echo '<!-- ' . basename( get_page_template() ) . ' -->'; ?>
And,
global $wp_query;
$template_name = get_post_meta( $wp_query->post->ID, '_wp_page_template', true );
will give you the template file name. Use str_replace() to strip the .php from the end.
`
I am using filter hook to insert a featured image into the_content, that works, but when I try to wrap the featured image in an anchor tag, the link tag ends up directly after the content(not wrapping the image at all)
Is there something I am missing as far as understanding how to filter the_content()? Here's my code:
add_filter('the_content', 'add_img_to_ps_archive');
function add_img_to_ps_archive($content) {
if (is_post_type_archive('past_symposia') ) {
echo $content . '<a href ="#" "alignleft">' . the_post_thumbnail('symposia-thumb') .
'</a>';
} elseif( is_singular('past_symposia') ) {
echo $content . '<br />';
} else {
return $content;
}
}
Try to use commas ',' and not dots '.' for concatenating - don´t ask me why, but wordpress does that sometimes...
This happened because the_post_thumbnail() outputs the image tag directly to the output buffer. You need to use get_the_post_thumbnail() to return the image tag so you can concatenate it with $content.