Brief explanation of our need: When we use a pullquote in a post we want it filtered out/hidden from the RSS feed, while at the same time continuing to show up in the content when viewing the post on the website.
Fuller explanation of our need: A pullquote highlights a specific piece of content from an article/page/post by repeating the content and bringing it slightly outside of the flow of the article/page/post content. This works well when using CSS, because it makes it clear that it is not to be read in the flow of the article's content, but to highlight a good sentence or two. Pullquotes are repeated content. However, in an RSS feed, the repeated content is awkward. We'd like to automatically filter out all pullquotes from our blog content on RSS feeds, while keeping it in the post content for frontend viewing.
What have I tried?
I've tried this plugin and it didn't work: https://wordpress.org/plugins/content-visibility-rss-feed/
I've read this, but don't know how to make it work for filtering pullquotes: Remove certain elements from an RSS feed such as short codes
I've read this, and while he outlines the problem well, we need a PHP solution and not a JS solution: https://css-tricks.com/better-pull-quotes/
I've read this stack overflow post, but we don't want to use custom fields: Hide/block page elements from RSS feed
A friend provided this code that I've tested, and it works well.
// Remove all Gutenberg pull quote blocks from feeds
function theme_filter_pull_quotes( $content ) {
return preg_replace('#<figure class="wp-block-pullquote(.*?)</figure>#', '', $content );
}
add_filter('the_content_feed', 'theme_filter_pull_quotes');
As you can see, the opening tag is not closed because depending upon your block settings, Wordpress may add other classes which would not match the pattern. Leaving the tag opened allows any additional classes to be included. It seems wp-block-quote is always the first class.
Related
Joomla! generates the meta tags before the title tag, For SEO Purposes, I would like to change it the other way, first title, and then meta tags, CSS, JS and other stuff.
I know I can do it by changing the order in the head.php file, but hacking the core files is very bad because when I'll want to update the system version, what I did will be removed.
Is there any other way to do that? maybe from the template or even by an extension?
One way would be to write a plugin to re-order this section via a regex search-and-replace before the page is displayed on the screen.
Looking at head.php, the simplest solution I can think of is that I see that it sniffs to see if a meta tag exists before outputting it to the page (sadly, it does not do this with the title tag).
In your template, you could always save the meta data values in parameters, then unset it each one with code along the lines of
JFactory::getDocument()->setGenerator('');
You could display the head as normal below this (which should now have the title at the top due to having no meta data to display)...
<jdoc:include type="head" />
... before hardcoding your metadata using the saved parameters beneath this.
The above all said, I would really question your SEO. I cannot think of a single reason why Google should penalise a site for having a title tag below the metadata. If it was a well known SEO no-no, then Joomla would likely have updated it - it would be a very small bug to fix. It sounds like SEO hearsay rather than anything real, and so fixing it would be bulking up your codebase for no good reason.
I need to insert a google adsense square box in the middle of all articles on the site.
What is the best approach?
The site is in drupal, so I figures I can hook to the view node function. this way the ad won't be saved together with the article. does that make sense? If so, than the question is how do I ensure I won't have image on the other side of the ad (the ad is aligned to the left and should take 50% of the article width)?
should I be using a block? but how will I know to place the block in inside the block.
So in short, I really have no idea where to start to implement it... How is this thing implemented in all the news sites?
I'd approach it by implementing a custom input filter that would insert the AdSense code (or the AdSense module shortcode, if you want) into the processed text. Once you have that custom filter implemented, you'll have to enable it in the text format you're using for the content type.
For implementing a custom filter, take a look at filter_example here.
This solution is for Drupal 7. The solution which worked for me is that I used the adsense tags format and then used this format to show ads on the site. Note that this line doesnot need any js inclusion or script tags. You just need to enable the Adsense tags format(I mean shortcode). Actually I was getting Ads disabled for admin and for other users i was getting the empty ad with space occupied on page but nothing shown. After different tweaks and experiments I got the following code working for me
[adsense:336x280:XXXXXXXXXX]
2nd parameter is width x height
3rd parameter: XXXXXXXXXX denotes the google ad slot/id.
I hope this will help others.
Ata ul Mustafa
I need to insert a google adsense square box in the middle of all articles on the site. What is the best approach?
From my experience:
On some drupal sites I used simply node editor to put box with adsense into content. For websites with not many nodes its best solution because of:
1) Box perfect fits in rest of content - you can change it manually.
2) Total control of viewed boxes - images, flash, text adds etc.
Etc.
But for websites with many nodes, this solution looks like stupid suicide.
Better option will be change node.tpl file in your theme folder. But there is some trouble. In this file, you have $content variable, with contains all of content in this node. This situation gives you ability to put box up or down of this node. But no in the middle. Perhaps solution will be to divide $content into 2x variables which will contains a half of contents. But question is - how do to it? Or maybe while content from node is saved into database, then you can put some html code with adsense box? And search best position to put box by regular expressions? Or maybe change all of nodes by adding html box directly in database?
should I be using a block? but how will I know to place the block in
inside the block.
As I remember, you cannot put block inside another block.
How can this be done?
Now I use fulltextrssfeed.com and WP robot, but I don't really like it, because fulltextrssfeed.com posts only like 5 articles when it was more than 50 in the original RSS feed. And all the plugins I tested (FeedWordPress, RSS poster, WP-o-matic, WP robot) couldn't post full articles from every feed I used.
The feeds themselves don't contain the full text of the articles.
What fulltextrssfeed.com does is fetching the URL of the feed entry and extracting the full text from there. This is what you have to do, too - if you want all the articles
you can use http://www.feedsapi.com/ or http://fivefilters.org/content-only/
You can use the api provided by full post rss feed, which extracts 10 posts from the rss feed, it is basically hosted version of fiverfilter premium Api. Fivefilter regularly updates their templates to extract the content from the major themes and sites.
If it is not able to extract the rss feed from any site, then you can add the template for that site, that means, template is something which will provide the details of tags and class to extract the content. For example, In wordpress, mostly the content will start from article tag or Div tag with some class. If you know any one programing language, then you can write your own rss parser and full content extracter using curl or any other method. It is very simple, you need some bandwidth to understand the concept.
I'm trying to create an auto generated post excerpt from the current page's post content using a function in my theme's header file. The post excerpt will be used as the page's meta description. Can someone give me an idea of how you might go about this once you've got the post content into a string variable?
The somewhat tricky part is that, in order to predict a viable stopping point for the post excerpt, I'd like to specify that the cutoff point be the end of the first paragraph of text.
And for that reason, it does not make sense to load the entire post content into the string I'm using. Can I grab the first paragraph without having to load the entire post content string?
And I'm not certain how to test for that in php. Would regex be the only way?
You can't parse HTML with regex. Posts are stored formatted in HTML (i.e. <p></p> <br /> etc).
I'm also assuming you are implementing this on a blog with lots of existing posts.
What you can do is:
Retrieve the post and run it through an XML Parser. Grab the first paragraph. This is incredibly expensive for such a simple task.
Use a quick tag in the post to denote the excerpt stop point, strip HTML from everything to the left of it. Similar to the <-- more --> tag.
Store an excerpt with each post, I believe WP already has facilities for that.
It would be much, much easier if you could simply select the excerpt without having to do any additional fiddling in order to use it, so the time to handle it is when a post is saved.
So, if you can initially select each post, parse it, get the first paragraph and insert it into another table, then have your plugin do that when each new post is saved, you're home. Naturally, you'd update the same if a post was edited (making that optional).
Just please, please, please don't introduce a plugin in WP that uses regex to parse a context free language. Its just asking for trouble.
In my theme I'm trying to display the excerpts or teasers of child pages, yet I do not want to display any images, I want image tags stripped out.
Once I've gotten the teaser in all its html glory in a php variable, how do I strip out the img tags prior to using echo?
And after you got the content in a html variable a small regular expression should do the rest
$content = preg_replace("/<img(.*?)>/si", "", $content);
Should do the trick
You probably want to use the semantics of in your pages, similar to how post excerpts work. You can get the list of subpages http://codex.wordpress.org/Template_Tags/wp_list_pages from here and then iterate over them (the above document has an example for styling the names of pages). you can then get the page contents with a custom function and do whatever you want with it.
http://www.mattvarone.com/wordpress/functionsphp-wordpress-themes/
That url explains how to add your own custom functions to a given theme.
You could use the the_excerpt() which automatically grabs just the text or you can use a more sophisticated version of the same thing called The Excerpt Reloaded