I've tried creating a post with a video embedded into the post (e.g. html instead of visual), and at the same time also insert an embed code into the template (e.g. single.php) The source view of those two code look identical in format, two videos are both visible on the page, yet only one video shows in RSS feed. The one that's embedded into the post.
Anyone knows why this is happening? I want my video to be called using a function, and still work in RSS, but I don't think I can do that unless... I know the differences? At least maybe I'll know what other operation I'm missing.
If you're embedding the video in single.php, you may have put it outside of the loop, ie. outside of
<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
(more of the loop)
<?php endif; ?>
and as result not showing up in RSS.
If it's in the post via the post editor, it's inside the loop and available as RSS as a single post.
If you need to execute php in a post/page, there are plugins for that.
Related
I'm absolutely new to WordPress theming but I decided to learn on the job and I really want the site to go live within the next week or so. I've stuck to a simple index.php (no templates or template-parts). I'm able to receive the contents in the proper format which they were published (with inline images, line breaks, etc.) but the css styling is absent. What could I be doing wrong?
<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<div class="entry-content">
<?php
$content = wpautop(get_the_content());
echo $content;
?>
</div>
</article>
I realize there is a difference between the singular view and the list view (the loop). The list view doesn't actually style the content by default. Could that be where my problem lies, and if so, what's the best way to get around this problem?
EDIT
Essentially, I want the singular view (singular.php) within the index.php. When you visit the site you're greeted by an entire article, not previews and listings. So I don't actually need the loop for now. I simply retrieve the post and display the contents on the index page.
That is literally the only thing keeping my site from going online right now. I just need that article to be styled as it's supposed to be. There are only two files in my theme: index.php and style.css. I've already tried the_content(), I've also tried apply_filters('the_content', get_the_content()), to no avail. wpautop(get_the_content()) was the closest thing to styled I could get. I am retrieving the post using the_post() for now, could that be the issue, and if so, which is the best way to retrieve a post?
I have tried retrieving the post in various ways and it's still unstyled, so I decided to inspect the elements in the browser and found that WordPress is indeed attaching a class to the elements but just where on earth is that class? I read somewhere about a css reset being the possible cause -- how does one bypass any css reset issues?
It turns out it was just a header issue. Solved by adding:
<head>
<?php do_action('wp_head'); ?>
</head>
I am having a weird issue.
Normally when you paste a youtube video the video will embed properly automatically. However when I paste a link into the visual view I can play and see the embedded video in the EDIT view, but on preview or publish it echoes out the link without embedding it as plain text.
So far I have tried disabling all plugins (except Advanced Custom fields)
Using the [embed] shortcode
Changing the youtube links from http to https
What does work is pasting the embed code from Youtube, or writing <iframe> in the text view.
It also works fine to paste and embed when I change theme
For me the issue was I was using
<?php echo get_the_content(); ?>
Instead of
<?php the_content(); ?>
As per the Wordpress Codex:
An important difference from the_content() is that get_the_content()
does not pass the content through the the_content filter. This means
that get_the_content() will not auto-embed videos or expand
shortcodes, among other things.
https://developer.wordpress.org/reference/functions/get_the_content/#:~:text=An%20important%20difference%20from%20the_content()%20is%20that%20get_the_content()%20does%20not%20pass%20the%20content%20through%20the%20the_content%20filter.%20This%20means%20that%20get_the_content()%20will%20not%20auto%2Dembed%20videos%20or%20expand%20shortcodes%2C%20among%20other%20things.
Use the [video] short code instead. It is incorporated in the Wordpress core nowadays. Go to this link for more info: https://codex.wordpress.org/Video_Shortcode
For example:
[video width="640" height="360" src="/wp-content/uploads/files/movie.mp4"]
May this not work in a custom theme, then you want to look at how the content of the post is being processes. You may need to apply the the_content filter to the post content variable like this:
apply_filters('the_content', $post->post_content);
I want to integrate specific text (text, links, images) making reference to specific sentences of my blog post.
Is it possible to do it with code or using a plugin ?
I send you a sketch :
This is the sketch
That is common need and often Aside in WordPress is talked for it. There are WP plugins like Aside Widget, Custom Sidebars for ordinary needs. But if you need too much custom stuff like my website's "About this Article" sidebar widget - https://thecustomizewindows.com/2016/09/limitations-of-openvz-virtualization-to-guest-cloud-server-vps/ then it is better to use
Otto's this plugin to use PHP in text widget - https://wordpress.org/plugins/php-code-widget/ and use PHP. In my case, rest is PHP code like this on sidebar (I can use shortcode too) :
<?php if(is_single()) : ?>
<h3>About This Article</h3>
<strong>Title:</strong> <?php echo get_the_title(); ?><br />
Published on: <?php the_time('Y-m-d') ?>
<br />
...
// rest of the code
<?php endif; ?>
Obviously you can call post image thumbnail with WordPress function.
As you need specific text, you may think about combining Pull Quote Plugin or Aside Widget to mark the specific like and echo it with PHP.
As other options -- you can use CSS3 to automatically select first line, first paragraph, second sentence. You can use Javascript to conditionally mark.
Best possible customisation I saw is on BMJ's sidebars. They use Drupal, not WordPress. BMJ has beautiful sidebar -- (as example) - http://www.bmj.com/content/355/bmj.i4924 Drupal has description of the work - https://www.drupal.org/node/1557636 Sadly I lack idea about Drupal. I tried a lot behind using WordPress for academic purpose.
this is my first time posting on this site so apologies if the question isn't totally appropriate but I'm building a portfolio site for my brother who is a composer and he needs his music library to be able to be checkbox filter-able. The problem is that when I conduct a search with filters, the results show only the excerpt, and not the audio player like I need.
Library page displaying the full posts with audio player
Search results page showing just the post title and nothing else
Also, excuse the sheer crudeness of the site. I just started it this morning... Thanks in advance!
To show the full content you have to use the_content function, in your search.php file replace the following
<?php the_excerpt(); // partial content ?>
with
<?php the_content(); // full content ?>
Also remember. the_excerpt function strips out all HTML tags so it could be a problem, you can read this article.
I am developing one wordpress site. I have made one post in it. Now I want to assign image in that post. For this, I have uploaded one image in media and attach that image to my post.
but how can I assign that uploaded image in my post? do I need to give path manually? or I can give dynamic path so that even if I upload this site on server or change main folder name, path gets changed automatically..
any help will be appreciated..
thank you
You should consider using Post Thumbnails (also known as Featured Images) in your posts. To do this, all you need to do is add the following to your functions.php file:
add_theme_support('post-thumbnails');
This will add a control in your Post Editor to add an image by either Uploading it or setting the URL, effectively "attaching" your image to your post in the way your looking for. To display the image in your template:
<?php
if(have_posts()) : while(have_posts()) : the_post();
if(has_post_thumbnail())
echo '<div class="post_thumb">'.get_the_post_thumbnail().'</div>';
?>
<div class="post_content"><?php the_content(); ?></div>
<?php
endwhile;endif;
?>
As for changing folder names, paths, etc. you need to be careful with that approach. Remember that you're giving a path to an asset. The server doesn't know what YOU want, only what your code is requesting. If you expect to be changing paths to your assets around quite a bit, then you can always forgo Post Thumbnails in favor of clever naming conventions. Something like this:
<?php
if(have_posts()) : while(have_posts()) : the_post();
$imgPath = get_bloginfo('stylesheet_directory').'/images/featured_'.$post->post_name.'.jpg';
?>
<div class="post_thumb"><img src="<?php echo $imgPath; ?>" /></div>
<div class="post_content"><?php the_content(); ?></div>
<?php
endwhile;endif;
?>
This looks for an image in your Theme Directory's images folder that is named featured_{post_slug}.jpg
The benefits to this approach is that Wordpress will always know where your theme folder is, regardless of URL changes. As long as you have an images folder in your theme directory, Wordpress will know where to look.
The drawback is that this code specifically doesn't first check for the EXISTENCE of the image before displaying it, which could lead to broken images if they aren't named properly or don't exist at all. This approach also requires the use of one file extension
A last option for you is to consider using Custom Fields to define paths to images. The benefit is that this does not require you to actually upload images to your server. However, this approach is still the least dynamic out of all of your options, and will likely break if paths to assets are changed.
Use whichever tool you feel is best for the job. Hope this helps!