Wordpress discontinuity between Excerpt and its 'more-button' - css

I'm building a custom Wordpress theme.In my index.php page i'm looping to display the excerpts for all of my blog-posts.
this is how I break the post flow:
//At first I place <!--more--> in my post-text where I want to break it..
the_content('more');
Now the point is I'd like to place the 'more' button not right after the excerpt.I'd like to place this button in another div containing other link-buttons (tags,comments-count ecc).
The only thing I came up with is using a span around the 'more' button (with absolute positioning).
Is there any better solution?
thanks
Luca

The fact that WP injects the read more link into excerpts, rather than just giving the formatted excerpt, has always been a problem for me, too. Especially since what surrounds the link is dependent on where the author placed it: inline or on a new line, before or after an image, inside or outside inline markup. Here's what I've done in the past -- I'm not sure whether this is the best solution but it should work...
get the raw, unformatted post content: $content = $post->post_content
get the excerpt by using explode("<!--more-->", $content).
run the excerpt through the the_content filter: $excerpt = apply_filters("the_content", $content[0]);
Balance the tags... $excerpt = force_balance_tags($excerpt)
On the whole, a better solution may be to ask authors to provide a text excerpt to go with each post rather than relying on this kloodgy method.

Related

Wordpress automatically adding paragraph

So I am working on making a child theme of the "twenty fifteen" theme.
So far I have made custom post types with custom fields. It is imperative that I use custom fields for adding Soundcloud embedds. I have used the "Advanced Custom Fieds" plugin to do so.
Now, the problem I have is that whenever I use the custom field to add a soundcloud widget (just by pasting the link) it seems that the WYSIWYG Editor is adding the link inside a paragraph like this
<p>https://soundcloud.com/skitofficial/skit-ghost-dog</p>
This causes (I think) a white line (a new paragraph) to appear below the Soundcloud widget.
As you can see in the picture below, if I open the code view of the WYSIWYG I can spot the paragraph lines being added around the link.
So all in all, the main problem for me here is the white space below the soundcloud widget. Perhaps it does not have to do anything with the paragraph tag, but either way I the space below the widget looks bad, unprofessional and I need to remove it somehow. Now you may say "why don't you just remove those paragraph tags?" and that is the problem, even if I remove them, they are added automatically.
So, any suggestions would be very appreciated. I have worked my head on this for three days without any progress.
Edit: this question is old and I do not have the site anymore.
I would just add this style to a global stylesheet:
.SoundcloudEmbedd p { margin: 0; }
seems safe
Wordpress WYSIWYG pops in <p> tags. If you're not careful, it will <p> all over your content.
https://codex.wordpress.org/Function_Reference/wpautop
Pop this into your functions.php
remove_filter( 'the_content', 'wpautop' );
EDIT
If you're using ACF, the text area field type has an option for whether or not to add the <p> tags. As mevius suggests, depending on your use case, you may want to consider using the URL field type.
OR, you can use this when calling the field in your theme.
the_field('wysiwyg_field', false, false);
It's possible that the WYSIWYG is adding those <p> tags, due to WordPress's wpautop function.
Rather than completely disabling wpautop, you could remove the <p> tags using a combination of get_field() and wp_strip_all_tags():
echo wp_strip_all_tags( get_field('field_name'), true );
EDIT: On second thought, why are you using a WYSIWYG for this at all? If you're just pasting a link, you should consider using a text field, or a url field.
I did not have access to the code, nor I had access to any plugins, hence I tried this only using the WYSIWYG editor.
To remove the any unwanted paragraphs from any particular web element like div just follow these steps:
add a class to your div (the div which is containing that unwanted paragraphs).
Write a javascript function using querySelectorAll.
Example Below:
var blankps=document.querySelectorAll('.removePara p');for(var i=0;i<blankps.length;i++){blankps[i].remove();}
<div class="col-xs-12 col-md-3 removePara">
<p></p>
How to Remove Empty Paragraphs. Solved.
<p></p>
</div>
Note: This will remove all the paragraphs inside any div which has class="removePara".
Hope this helps someone.

Adding A Button Between post-content and Related Posts Thumbnail Plugin on WordPress

I am trying to add a button to my WordPress template. Basically, I have the post and then there is the Related Posts Thumbnails widget that appears. I want the button to go between the text of the post and the related posts thumbnail widget. The code in my 'Single Post' that contains all of this is as follows:
<div class="post-content">
<?php the_content(__('<em><strong>More:</strong> Read the rest of this entry...</em>', 'life-is-simple')); ?>
</div>
I know the Related Posts Thumbnails plugin falls within this code because it's at that place when I 'Inspect Element' on Google Chrome. I can't find how to edit the order of things within that div though. Any help would be greatly appreciated, thanks!
EDIT
Clarification: I am using the Life Is Simple WordPress theme although it has been custom editing quite a bit (mostly on the CSS side of things though).
That plugin is probably appending the output to the_content with a filter .
That means , that the output is being added to the_content automatically. it is a common behaviour.
You need to look at the plugin´s admin interface to see if you can have an alternative way (I believe there is ) which is using a template tag. in that case, you should put the template tag after the div where the the_content() is .
EDIT I :
After a small dig, - in fact there is - you need to put
<?php get_related_posts_thumbnails(); ?>
Then the plugin should know by itself not to append to the_content.
For parameter passing, or if something is not working, go read their APi or help files.
You'll probably need to edit single.php or archive.php in your theme. If nothing is occuring there that looks familiar, it's probably using a loop. In which case you might find what you are looking for either in loop.php, loop-single.php, or loop-archive.php depending on what type of page you are on and how the theme was constructed. Add your button near where you find Read the rest of this entry...
With more information (such as what theme you are using), one might be able to help more as well.

How to add search box to drupal page contents (404 page)

I have a theme where search box is hard to find.
Before redesigning it, I'd like to add another, bigger search box to 404 page.
The only solution I found is render search block:
<?php
$block = module_invoke('search', 'block_view', 97);
print render($block['content']);
?>
This is not good solution because one have to find block number first.
How to use search_box() function properly?
Maybe you'd want to try using http://drupal.org/project/search404? I'm not sure if you can disable automatic searching on a 404 page but it's very close to what you are needing without custom code.

WordPress Editor Image for Shortcode

Quick question about WordPress. I've been Googling all over the place and cannot find an answer.
Basically I'm looking to replicate what happens when you add a gallery: have an image displayed as a stand in for the gallery shortcode [gallery]. The shortcode's visible when you go to edit HTML.
I'd like to exactly copy this effect: When a shortcode inserted into the editor I'd like for to to be rendered as an image.
Things I've Tried:
Inserting an element (image, div, I found an input is pretty unfuckwithable, etc) that's wrapped by a shortcode (This works ok, not great. The short code's still visible and WP will auto add paragraphs to the element to create space that users could, possibly, add content that'll be eaten by the short code) -
Inerting the short code as a < !-- --> comment (This also doesn't work great, WP will occassionally eat it moving between Visual/HTML. The comments ALSO eat your content < !-- [shortcode]--> placeholder < !--[/shortcode] --> = < !-- rendered shortcode -->)
That's the extent that I've thought of things. I cannot find a guide on how to do mimic the [gallery]'s behavior and can't find it by going through wp-admin's guts.
Thanks!
Alright, found the answer thanks to Dan's hint. Here's how to do it:
First (as Dan suggested) take a look at how they add the Gallery plugin to Tiny MCE. There's actually an uncompressed js file that will give you the overview you need, find it in:
/wp-includes/js/tinymce/plugins/wpgallery/editor_plugin.dev.js
This goes over the basics on adding this type of plugin to TinyMCE (more info here). To get WP to load the .js file with your TinyMCE plugin, see this helpful guide.
Basically here's the code:
if ( get_user_option('rich_editing') == 'true') {
add_filter("mce_external_plugins", "add_jolokia_tinymce_plugin");
//Applying the filter if you're using the rich text editor
}
function add_jolokia_tinymce_plugin($plugin_array) {
$plugin_array['example'] = '/path/to/example.js';
return $plugin_array;
}
Add this to a plugin or function.php in a theme And you're good!

Wordpress: apply_filters & add_action to the_content = EVIL?

I asked this question over in the actual tutorial, but not sure I'll get an answer anytime soon as it's almost 2 months old... so I'll take a gander here...
Tutorial is here: Build a WordPress Plugin to Add Author Biographies to your Posts
To sum up the tutorial and what the problem is, The tutorial adds an Author Bio on to the end of the content like so (the short version):
function x($content) {
return $content . "Author Bio";
}
add_action('the_content','x');
The Problem:
When someone uses:
$z = apply_filters('the_content', 'some content here');
echo $z;
The Author Bio will end up applied to $z and if $z is echoed out in the middle of some page… the Author Bio would be in the middle of some page… correct? (it's correct because I've tested it...)
Is there a better way to apply something to the end/under/below the_content hook? other than add_action(‘the_content’, ‘some_function’) because this to me seems evil...
or is apply_filters(‘the_content’, ‘some content here’) not the norm or something developers shouldn't be using inside their WordPress templates…? (which seems pretty much the norm, at least upon Google-ing formatting "the_content" outside the loop)...
Using apply_filters('the_content','some content here'), while it may not be 'the norm' (I don't know. I haven't seen it before, but if I needed formatted text, that's what I'd do), is a perfectly valid use of filters to get some text formatted like the content. Unfortunately, there's no better way to append something to content from a plugin. That is just the way these things work.
However, there's a (less than optimal) way of circumventing this. As part of the setup/install process for your plugin, have the user insert a custom function call, action, or filter into their theme. I know several plugins that do this, so it's not all that uncommon. Something like this:
do_action('my_super_awesome_bio_hook');
Would allow you to hook in without worrying about adding a bio to unexpected (and unintended) content. Even better would be inserting a filter:
echo apply_filters('my_super_awesome_bio_filter_hook','');
That would allow your plugin to modify the bio, but also allow the one using the plugin to override it if necessary (like on pages where they're just using excerpts, like search results, etc.).
Hope this helped.
Also, one minor addendum: you should be using add_filter, not add_action to append the Author Bio. add_action still works, but it's a filter you want to be using.
I bumped into a similar issue with a widget I'm dev'ing. I just found this:
http://codex.wordpress.org/Function_Reference/wpautop
Which I'm now going to use instead of add_filters('the_content'). I want the WYSIWYG formatting but I don't want things append to my content because it's not traditional content anymore.

Resources