Wordpress shortcode not working - wordpress

I built a very unique and javascript intensive theme for wordpress and now shortcodes do not work. I do not have any plugins installed, so it's not that. What did I drop from my wordpress template files that is required to use shortcodes (ie: [gallery]).
I understand how to make shortcodes, but how does WP take your post and replace "[gallery]" when it is spitting it back out for display?
EDIT:
here is what I'm currently working with:
$pagepull = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' ORDER BY menu_order", ARRAY_A);
$i = 1;
foreach ($pagepull as $single_page){
echo "<div class=\"section\"><ul><li class=\"sub\" id=\"" . $i . "\"><div class=\"insection\">";
echo $single_page['post_content'];
$i++;
// more code that is irrelevant...
// more code that is irrelevant...
// more code that is irrelevant...
}

Ok, try this
$pagepull = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' ORDER BY menu_order", ARRAY_A);
$i = 1;
foreach ($pagepull as $single_page){
echo "<div class=\"section\"><ul><li class=\"sub\" id=\"" . $i . "\"><div class=\"insection\">";
echo apply_filters('the_content',$single_page['post_content']);
$i++;
Wordpress take your content and apply filters to it. You must register a filter and let parse your content.
If your theme is not displaying your shortcodes, probabily you output the content of the post without let Wordpress filter it.
Calling the function get_the_content() for a post, does not run the filter for shortcodes (if any).
To have apply
<?php apply_filters('the_content',get_the_content( $more_link_text, $stripteaser, $more_file )) ?>
Ref: http://codex.wordpress.org/Function_Reference/get_the_content
Note: many plugins register filters with the content to implement shortcodes!

My solution was replacing
<?= get_the_content() ?>
with
<?= the_content() ?>
which, as keatch already mentioned, applies filters before returning content.
Read this carefully about the_content

use this if you want the content inside a variable:
ob_start();
the_content();
$content = ob_get_clean();
now you could just do echo $content; or use regex or whatever you want to make the content look like how you want it.

I had the same issue.
Shortcodes depends on WP Loop, but that's a different issue. To make a long story short, I've added the_post(); at the page that should be showing the shortcode (for example articles.php).
Also, make sure that you are using the_content() in order to display the text (using $post->post_data for example won't show you shortcodes).

Please use the
ob_start();
in the starting of function and use
return ob_get_clean();
before closing the function.
Hope this will help full for you.
Cheers

Related

Adding media support to a timeline plugin (Wordpress)

I have installed this plugin -> http://wordpress.org/plugins/wordpress-posts-timeline/ .
With this plugin you can create a post and it displays in a timeline. My problem is that images don't show when inserted in the post box.
I tried modifying the plugin code and put some get_attachment code inside the loop there but unfortunately didn't work.. I can get all images to show, but not by ID of the post.
Youtube support would be nice too, but maybe that gets clear if this question is answered.
Current state -> http://erwin.my89.nl/stage/sieh
// Edit
I have tried alot of code with wp_get_attachment stuff.
<?php
wp_get_attachment_image( $attachment_id, $size, $icon );
?>
&
<?php $uri = wp_get_attachment_image_src( $post->ID, 'medium' );
echo $uri[0];?>
But cant get it to work..
Thanks in advance.
The plugin is stripping HTML tags when building the content:
function timeline_text($limit){
$str = get_the_content('', true, '');
$str = strip_tags($str);
// etc...
You have to add <img> (and others) as an allowed tag on strip_tags():
$str = strip_tags($str, '<img>');

how to retrieve custom fields on taxonomy page?

I am using the "advanced custom fields" plugin and need to have it so that a custom field is pulled in for the category pages. I can get these to come in on pages, but the category pages are giving me a lot of trouble... 'video' is the name of the custom field I want to pull in.
This is the code I am currently using:
<?php echo get_field('video', 'clear-creek'.$wp_query->queried_object->term-4); ?>
or just a standard version like this which works on the regualar pages...
<?php the_field('video'); ?>
but it's not working... can someone please help steer me in the right direction?
Thanks!
If you are on a category's archive page, you would use this:
<?php echo get_field('video', 'category_'.get_query_var('cat')) ?>
If you are on a custom taxonomy instead, you would use this:
<?php $queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
echo get_field('video', $taxonomy . '_' . $term_id); ?>
This will dynamically get the taxonomy's slug and ID, and build out your get_field based on that information.

How to show tag/skill type to a dynamic post in Wordpress theme Classica

I use this theme:
http://demo.themezilla.com/?theme=classica
Under the "recent projects" i want each posted portfolio post to display what kind of tag/skill-type it is connected to. This can be checked in the wp-admin page when you create a new portfolio post. I don't know what function i need to write in php to make this work.
Is there any easy way to solve this like when you show a posts excerpt?
<?php the_excerpt(); ?
I think you can use like this.
<?php the_tags( '<p>Tags: ', ', ', '</p>'); ?>
If it's stored as a custom variable (appears below the post content when editing it in the admin panel), you can usually access it like so:
get_post_meta($post->ID, 'key_name_here', true);
Check out the get_post_meta() Code Page for more details on the function.
Use get_the_term_list() to get the skill-type and strip_tags() to remove the links
$terms = get_the_term_list( $post->ID,'skill-type', '', ', ','' );
$terms = strip_tags( $terms );

How do I get the name of the file that is being used to render the current page?

Let's say I have a WordPress installation, with a page named "About". If I go to http://example.com/about, I know from WordPress' template hierarchy page that I'm looking at the theme file page.php.
I'm wondering if there's a way to display that fact (for theme debugging) on the page somewhere? Like what function (or code) would I call to display the current PHP page that is being used to render the page I'm looking at.
I could do something with $_SERVER['PHP_SELF'], but I'm looking for a way where I don't have to edit every PHP file. Like something that spits out the list of files it's using as the pages are called.
It can be printed in the Html source code like this:
add_action( 'wp_head', 'so_9405896_show_template', 999 );
function so_9405896_show_template() {
global $template;
echo '
<!--
TEMPLATE = ' . basename($template) .'
-->
';
}
Or for easier visualization, directly in the content with this:
add_filter( 'the_content', 'so_9405896_the_content_filter', 20, 1 );
function so_9405896_the_content_filter( $content )
{
if( is_admin() || !current_user_can( 'administrator' ) )
return $content;
global $template;
$the_templ = '<strong style="background-color: #CCC;padding:10px">TEMPLATE = '
. basename( $template ) . '</strong><br />';
$content = sprintf( $the_templ . '%s', $content );
return $content;
}
Which results in:
As far as I've seen there's no built in option to enable such logging, only for errors.
I'm not sure what editor you use, but most common text editors allow you to do a find replace across an entire folder.
I'd suggest doing a temporary replace on includes and require's to add an echo of the PHP_SELF. Just make sure to add a comment or something before the echo so that you can easily replace them with nothing when you're done.
A quick search on the WordPress plugin repository brings up a WordPress Debug Bar Template Trace.
I just manually type it into the template, i.e. ARCHIVE.PHP, CATEGORY-1.PHP when I'm building it. Just remember to delete it once the site goes live.
Simple and easy, if not so graceful.
For those looking for a newer answer:
<?php if ( is_user_logged_in() ) { global $template; echo basename($template); } ?>
This checks if a user is logged in, then only shows the template name. This can be handy if you need to hack your way on a live site without adding functions.

Can't get my WordPress site to update its own feed?

I'm using the following code to display some entries of my WordPress blog as a feed in the sidebar. The problem is, it's not updating no matter what I do. It still only shows the first "Hello World" post, even though I've added others, and it doesn't even show the updated name of that post after I've changed it. Thought this might be a caching issue, but if I actually click into the feed XML, the data is updated- which makes no sense to me??
<?php
// Blog Feed:
$rss_url = get_option('home')."/feed/";
?>
<ul class="side-feed">
<?php if(function_exists('fetch_feed')) {
include_once(ABSPATH . WPINC . '/feed.php'); // include the required file
$feed = fetch_feed($rss_url); // specify the source feed
$limit = $feed->get_item_quantity(3); // specify number of items
$items = $feed->get_items(0, $limit); // create an array of items
echo count($items);
}
if ($limit == 0) echo '<div>(None)</div>';
else foreach ($items as $item) : ?>
<li><?php echo $item->get_title(); ?></li>
<?php endforeach; ?>
</ul>
Wordpress caches feeds for 12 hours by default, to change this you need to hook into the wp_feed_cache_transient_lifetime filter and return the number of seconds you want to cache for.
add_filter('wp_feed_cache_transient_lifetime', create_function('', 'return 60*60;'));

Resources