Wordpress Shortcode Displays as is on the Page - wordpress

I am using a Portfolio Plugin. And it asks me to add the following shortcode in to the page where i want to show the content
[nimble-portfolio template="2colmosaic" types="3,4,5" items_per_page="3"]
When i do the following
$view = get_page_by_title('View');
echo $view->post_content;
It displays
[nimble-portfolio template="2colmosaic" types="3,4,5" items_per_page="3"]
as text when rendered
Edit
I tried to do the following
echo apply_filter('the_content', $view->post_content);
But it doesn't Render the full page now. And stops upto that point.

Try this following code and let me know the case then -
<?php echo do_shortcode($view->post_content); ?>

Related

How to display featured image of HOVERED wordpress post in a specific DIV?

I want to make my websites first page so you have posts listed with only titles and meta.
When you found something interesting you'd put the cursor on the title (linking to the post) and that would display a featured image beside (either on a specific spot on the site or offset just enough to not cover any of the text or replacing the cursor).
Here is an example in action:
example of hover effect
I would put this code in a PHP snippet that I would add to a page with a shortcode. Right now the best I have is this:
<?php
echo '<div class="feauturedImg">';
$args = array('page_id => );
$featured_image = get_posts($args);
foreach($featured_image as $image) : setup_postdata($image);
echo the_post_thumbnail();
endforeach;
wp_reset_postdata();
echo '</div>';
?>
It should make a div and display the featured image inside it. I need to get the featured image of whichever post is being hovered dynamically. This is how I'd get the link of a hovered post in JS but I don't know how or if it's even possible to implement it.
I would need to pass it in to the PHP and get the post ID from it:
<script>
$('.hoverLink').hover(
function(){
var myHref = $(this).attr('href');
},
function(){
$('.hoverDetail').remove();
});
</script>)
Basically I need a way to get the hovered link from a JS or a way to save a hovered link into a PHP variable to than put it in url_to_postid() function and get the ID of the post to put into this section:
$args = array('page_id => );
(first PHP code) to display the right image.
Any ideas?

Wordpress shortcodes not working on posts but wornikg on pages

When I use shortcode on page works good but on posts is displayed only shortcode name.
Example shortcode:
function foobar_func( $atts ){
return "foo and bar";
}
add_shortcode( 'foobar', 'foobar_func' );
Usage:
[foobar]
On page is displayed
foo and bar
but on post only
[foobar]
I tryied on basic theme like TwentySeventenn and the problem still exists.
It's very strange. So you added the above code to TwentySeventenn theme's functions.php, but it does not work on post? Please double check you write [foobar] correctly on your post content file.
Or if you changed something on the theme, please check you used the_content() instead of echo get_the_content();
shortcodes are not working if you use get_the_content();

Add Page Title to source key in url for use in a form - Wordpress Website

I am trying to add a waitlist button functionality to a page on my wordpress website. Basically I need to autopopulate the source key in the query string in a url with the page title.
More Details:
I have the button linking to a general waitlist form but I want the product information from the page title go into a text field. I can do this by using a source key in the url.
We have our product listed on a portfolio post here with a waitlist button: http://www.inventivewebdesign.com/renohifi/listings_portfolio/pass-labs-xa-160-8-monoblock-power-amps/
The button goes to a form here with a text field that auto populates with the source key in the url.
So if I use the link: http://www.inventivewebdesign.com/renohifi/waitlist-request/?source=Pass%20Labs%20XA-160.8%20Monoblock%20Power%20Amps, The source key will populate the the product text field with "Pass Labs XA-160.8 Monoblock Power Amps". This all works great!
Now, I want to automate the code for the button so it always pulls the Page title as the source key so we don't have to manually enter in code for each button.
How can I get the page title to auto-populate the query string in the link url so that the link will be http://www.inventivewebdesign.com/renohifi/waitlist-request/?source={PAGE_TITLE}?
FYI - I am using the Visual Composer plugin for page layout and button creation.
UPDATE:
I am trying to use code like this:
<div class="vc_btn3-container vc_btn3-center">
<a title="Waitlist - <?php the_title_attribute(); ?>" href="http://www.inventivewebdesign.com/renohifi/waitlist-request/?source=<?php echo get_the_title(); ?>">
Add Me to the Waitlist
</a>
</div>
It is in the Wordpress editor so the code is not showing up as anything other than code. I want the title to show (I am trying two different wordpress calls for the page title). You can see this in the 2nd "Add Me to the Wishlist" Button on the first link above.
In JavaScript you can get the page title from the DOM using document.title, the value is encoded using the encodeURIComponent() function.
Your URL as a JavaScript string:
var url = "http://www.inventivewebdesign.com/renohifi/waitlist-request/?source=" + encodeURIComponent(document.title);
I couldn't find any reference to the URL on the page to which you linked.
EDIT: To encode the title string using PHP you need to use the urlencode() function.
Template code:
<div class="vc_btn3-container vc_btn3-center">
<a title="Waitlist - <?php the_title_attribute(); ?>" href="http://www.inventivewebdesign.com/renohifi/waitlist-request/?source=<?php echo urlencode(get_the_title()); ?>">
Add Me to the Waitlist
</a>
</div>
I did it by adding a shortcode instead:
function shortcode_waitlist( $atts ){
$pagetitle = get_the_title();
$link = '<div class="vc_btn3-container vc_btn3-center"><a class="vc_general vc_btn3 vc_btn3-size-lg vc_btn3-shape-rounded vc_btn3-style-modern vc_btn3-block vc_btn3-color-primary" href="http://www.inventivewebdesign.com/renohifi/waitlist-request/?source='.$pagetitle.'" title="Waitlist - '.$pagetitle.'">Add Me to the Waitlist</a></div>';
return $link;
}
add_shortcode( 'waitlist_button', 'shortcode_waitlist' );
Then just used [waitlist_button] in the page.
Thanks for your suggestions, they helped me get to where I needed to go.

WordPress: How to pass “Blog pages show at most” value into shortcode inside a template

I’m using Ajax Load More plugin inside a custom WordPress theme by inserting a shortcode into my index.php template.
<?php echo do_shortcode('[ajax_load_more post_type="post" posts_per_page="10" offset="10" pause="true" scroll="false"]'); }?>
Is there a way to get the value of “Blog pages show at most” from Settings/Reading and pass it into the shortcode to automatically update its posts_per_page and offset values when “Blog pages show at most” value is changed inside the dashboard?
I figured it out, so I'll post it here if anyone else ever needs it.
$default_posts_per_page = get_option( 'posts_per_page' );
gets the number of posts set inside Settings/Reading.
Then simply add the variable into shortcode:
echo do_shortcode('[ajax_load_more post_type="post" posts_per_page="'.$default_posts_per_page.'" offset="'.$default_posts_per_page.'" pause="true" scroll="false"]');

Wordpress Page ID within Shortcode

I am using a plugin called: InPost Gallery. I have added the shortcode to a template file but the shortcode needs the post ID to find the images related to the page. Is it possible to get the post id added to a shortcode in a template file?
This is what I have at the moment:
<?php echo do_shortcode("[inpost_nivo slide_width='600px' slide_height='auto' thumb_width='75' thumb_height='75' post_id="28" skin='light' transition_effect='random' transition_speed='600' autoslide='5000' control_nav='1' control_nav_thumbs='1' direction_nav='1' direction_nav_hide='0' controlNavThumbs='0' random_start='0' pause_on_hover='1' show_description='1' box_rows='4' box_cols='8' slices='15' start_slide='0' id='' random='0' group='0' show_in_popup='0' album_cover='' album_cover_width='200' album_cover_height='200' popup_width='800' popup_max_height='600' popup_title='Gallery' type='nivo'][/inpost_nivo]"); ?>
You can see the post_id is set to 28. This needs to change depending on the page currently being viewed.
If this is possible it would be a great help to hear your suggestions.
Many thanks
If it's within the loop, you can for example use:
<?php
// Display shortcode for current post:
$s = sprintf( '[inpost_nivo post_id="%d"]', get_the_ID() );
echo do_shortcode( $s );
?>
You could also try to skip the post_id attribute, and see if it has the same default setup.

Resources