I am currently trying to do research on how to output a result from a WordPress custom plugin to the frontend of WordPress. I have trying adding filters, do actions, add actions. But nothing seems to work. I know the add_action works for child themes because I'm currently using a script to do so.
The script below works for the child theme but not in a plugins functions.php page.
function displayPages()
{
$pageIDs = "List of page ids";
if(is_page($pageIDs))
{
include_once 'script.js';
}
}
add_action('wp_footer', 'displayPages')
Here is the current code I was trying use to fix the problem with the plugin.
function getPageIDs()
{
include_once($_SERVER['DOCUMENT_ROOT'].'/stage/wp-config.php' );
global $wpdb;
$row = $wpdb->get_row( 'SELECT pages FROM schemalocalbusiness WHERE id = 1');
$pageIDs = $row->pages;
$pageIDsArray = explode(",", $pageIDs);
foreach($pageIDsArray as $perma)
{
echo ' ' . esc_url( get_permalink($perma) ) . '<br>';
}
}
function includeShemaOnPage()
{
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if(getPageID() == $acturla_link)
{
print 'SUCCESS';
}
}
add_action('wp_footer', 'includeShemaOnPage');
Any and all help would be much appreciated! Thank you in advance!
Related
I am needing help on this custom code I have created. The purpose of this shortcode is to display a clickable link to the customers order received page on the order received email. I want the link to be accessible for all customers including those that do not have an account. The order status when order is placed is on-hold if that helps.
function emailurlorder()
{
$order = wc_get_order( $order_id );
if ( $order ) {
$order->get_checkout_order_received_url();
return;
{
$checkout_order_received_url = $order->get_checkout_order_received_url();
if ($order_checkout_order_received_url) {
return $order_checkout_order_received_url;
}
ob_start();
$pay_link = $checkout_order_received_url;
$payment_text = __('Click here to pay','text_domain');
echo '' . $payment_text . '';
$contents = ob_get_contents();
ob_end_clean();
return $contents; '' . $payment_text . '';
}
}
}
add_shortcode('orderlink','emailurlorder');
What it is suppose to do is display a clickable link labeled as "Click here to pay" and the url is my websites order received page for that specific order.
Problem- Shortcode displays absolutely nothing not even the shortcode text ([orderlink]).
I am using the WordPress Advanced Custom Field plugin. I have a custom built download button and shortcode. Now I am using ACF fields to populate the download btn shortcode. Everything seems to be working and download button is displaying as expected. The only problem is that ACF fields are not populating in the shortcode but its showing outside the shortcode code.
<?php
if (get_field('dn_btn_url1')) {
echo do_shortcode( '[download_btn url="'.get_field('dn_btn_url1').'" filename="'.get_field('dn_btn_txt1').'"]' );
}
?>
The code without the if statement is working as expected but it doesn't hide the shortcode.
The get_field function gets the post id from the global $post object so when it's passed into the shortcode function, it seems like it can't get the right post id. Try putting your URL from the field into a variable so the URL is already passed through the function and into the shortcode function.
Try this:
<?php
if (get_field('dn_btn_url1')) {
$url = get_field('dn_btn_url1');
echo do_shortcode( '[download_btn url="' . $url . '" filename="' . $url . '"]' );
}
?>
You can do that by using sprintf function please try it once
<?php
if(get_fiedl('dn_btn_url1')) {
$url = get_field('dn_btn_url1');
$filename = get_field('dn_btn_txt1');
$shortcode = sprintf(
'[download_btn url="'.$url.'" ,
filename="'.$filename.'"]');
echo do_shortcode( $shortcode );
?>
I am supporting a website running on Wordpress 3.8 with a wpzoom theme (zenko) on top of that with most of the articles posts running on multiple pages.
For pagination navigation we use the WP-PageNavi plugin http://wordpress.org/extend/plugins/wp-pagenavi/ with the function
<?php wp_pagenavi( array( 'type' => 'multipart' ) ); ?>
inserted in the single.php code after the
<?php the_content(); ?> function.
Recently we added the WordPress Related Posts http://wordpress.org/extend/plugins/wordpress-23-related-posts-plugin/ . However when activated the related posts appear before the page navigation links- buttons and I would prefer to change it to appear after them.
Looking around in the related post plugin's code I found the corresponding formating code as follows:
global $wp_rp_output;
$wp_rp_output = array();
function wp_rp_add_related_posts_hook($content) {
global $wp_rp_output, $post;
$options = wp_rp_get_options();
if ($content != "" && $post->post_type === 'post' && (($options["on_single_post"] && is_single()) || (is_feed() && $options["on_rss"]))) {
if (!isset($wp_rp_output[$post->ID])) {
$wp_rp_output[$post->ID] = wp_rp_get_related_posts();
}
$content = str_replace('%RELATEDPOSTS%', '', $content); // used for gp
$content = $content . $wp_rp_output[$post->ID];
}
return $content;
}
add_filter('the_content', 'wp_rp_add_related_posts_hook', 10);
My question is how can I modify the code so that the array of related post appear after the page navigation links
Im creating a custom function for my wordpress website that will add a review section below the post content and i need to insert this function from another another file into a custom function that i added to my functions.php. I need to get this piece of code $buffy .= $this->get_review(); from a different file to work in this function:
function content_injector($content) {
global $wp_query;
$postid = $wp_query->post->ID;
if (is_single((get_post_meta($postid, 'top_ad', true) != 'off' ))) {
$top_ad = do_shortcode('[td_ad_box spot_name="Ad spot -- topad"]');
}
if (is_single((get_post_meta($postid, 'bottom_ad', true) != 'off' ))) {
$bottom_ad = do_shortcode('[td_ad_box spot_name="Ad spot -- topad"]');
}
if (is_single()) {
$review = //HOW DO I ADD THAT get_review CODE HERE?
$custom_share = '<div id="title-deel"><h4 class="block-title"><span>DEEL</span></h4></div>' . do_shortcode('[ssba]');
$facebook_comments = '<div id="title-reageer"><h4 class="block-title"><span>REAGEER</span></h4></div>' . '<div class="fb-comments" data-href="' . get_permalink() . '" data-colorscheme="light" data-numposts="5" data-mobile="false" data-width="700"></div>';
}
$content = $top_ad . $content . $bottom_ad . $custom_share . $facebook_comments;
return $content;
}
add_filter('the_content', 'content_injector');
As you can see i need to add the get_review function to $review, but i cant make it work on my own. How to make this work?
Use include to include the file before using any methods from that file.
include("file_with_functions.php");
OR
Create a class (with filename same as classname).
Include the file.
Create an instance of the class.
Access the method in the class through the object
This is my first time playing with filters, so forgive me if this seems basic. I have done quiet a bit of googling and can't find anything related to my problem, from everything I have been able to find this should be working without an issue. It's my understanding that filters added manually run concurrent with any other filters wordpress is automatically running, ie: creating my own filter will run along with wordpress's default wpautop and wptexturize filters.
But for some reason my added filter is running fine, except now wpautop and wptexturize is failing to run on the_content. After removing my custom filter from functions, the default filters are triggering again. No other plugins installed that are modifying the output. Any help would be super appreciated, along with any general recommendations as to a better way to do this if you see something wrong with my statements.
function tumblr_chat_post($content) {
global $post;
$content = $post->post_content;
if ($post->post_type == 'post') {
$postcats = wp_get_object_terms($post->ID, 'category');
foreach ($postcats as $mycat) {
if ($mycat->name == "chats") {
$chatoutput = "<dl class=\"transcript\">\n";
$split = preg_split("/(\r?\n)+|(<br\s*\/?>\s*)+/", $content);
foreach($split as $haystack) {
if (strpos($haystack, ":")) {
$string = explode(":", trim($haystack), 2);
//list($who, $what) = explode(":", $haystack, 2);
$who = trim($string[0]);
$what = trim($string[1]);
$row_class = empty($row_class)? " class=\"alt\"" : "";
$chatoutput = $chatoutput . "<dt$row_class><b>$who:</b></dt> <dd><i>$what</i></dd>\n";
}
else {
// the string didn't contain a needle so we will keep it and output it later
$no_chatoutput = $no_chatoutput . $haystack . "\n";
}
}
// print our new formated chat post and push unformatted content to the end of the post.
$content = $chatoutput . "</dl>\n" . $no_chatoutput;
return $content;
}
else {
// I don't exist in the defined category, so no processing is needed
return $content;
}
}
}
else {
// I'm not a regular post, so no processing is needed.
return $content;
}
}
add_filter( "the_content", "tumblr_chat_post", 20);
You're not passing the already filtered $content into your filter function (and therefore you're losing any filtering done before you reach your function). It should be defined like so:
function tumblr_chat_post($content) {
// rest of your logic m'ere
}