Need to turn this php into WP shortcode

I need to turn this code:

<?php if ( function_exists( 'echo_ald_crp' ) ) echo_ald_crp(); ?> 

into a shortcode. Can someone help me do this? I have researched but am just lost to be honest. Thanks!

Replay

Init your shortcode

add_shortcode('shortcode_ald_crp', 'myshortcode_echo_ald_crp');

The function what you want:

function myshortcode_echo_ald_crp() {
    ob_start();
    if ( function_exists( 'echo_ald_crp' ) ) echo_ald_crp();
    return ob_get_clean();
}

you call you shortcode in a post like this:

[shortcode_ald_crp]

Or into the php code:

echo do_shortcode('[shortcode_ald_crp]');

UPDATE

Change the function add_shortcode

shortcode_ald_crp for myshortcode_echo_ald_crp

Do you mean something like this (untested):

// function for your shortcode
function shortcode_action($atts) {

        ob_start();
        if ( function_exists( 'echo_ald_crp' ) ) echo_ald_crp();
        $content = ob_get_contents();
        return $content;
}

// creates shortcode [shortcodehandle] so change it accordingly
add_shortcode( 'shortcodehandle', 'shortcode_action' );

Update: using ob_get_contents to return the content of the output of echo_ald_crp.

Category: php Time: 2016-07-28 Views: 0
Tags: php shortcode

Related post

  • Turn a snippet of HTML and PHP into a shortcode 2013-06-24

    the code is <div class="huili-relevant-left"> <a href="<?php echo get_post_meta($post->ID,"taobao_value",true);?>" hidefocus="true" target="_blank" class="btn-buy js-log " data-

  • How to turn this query into a Pivot? 2016-01-21

    If theres something I can't learn, is PIVOT. People are trying to teach me this, I'm reading blogs about this but I just can't understand the logic. How can I turn this query , into a pivot? The query: select case datename(weekday,Vit_DataAberturaRea

  • Need to call this php function inside a modal window from text widget 2013-08-20

    Need to call this php function inside a modal window from sidebar text widget <?php echo get_post_meta( $post->ID, 'link', true ); ?> --------------Solutions------------- There are several examples on the net, however I use this: <?php //funct

  • How to turn this css into sass or scss for ruby on rails? 2016-07-03

    How to turn this css into sass or scss. I am trying to use this in my ruby on rails project. http://jsfiddle.net/fd3600yv/1/ I get dude nasty error when I try online converter. Invalid CSS after " width: ": expected expression (e.g. 1px, bold),

  • What kind of motor would I need to turn this central heating valve? 2014-01-22

    I often forget to turn my central heating down when I leave the house, so I thought it would be cool to make a device that could do it for me and to have a website where I can check and change the heating. I was thinking about using the Arduino with

  • How do I turn this form into a search form? 2015-02-15

    Hi I have an expanding search form inside the wordpress header and would like to make it work with my theme? https://jsfiddle.net/u08cutgf/ <div class="search"> search <input type="text" /> </div> --------------Soluti

  • How can I turn this cipher into a perfect cipher by altering only its encryption algorithm? 2015-10-13

    Given a toy cipher that picks a key, k, from the key space of {00,01,10} and a message,m, from the same set {00,01,10} and encrypts using E = m ⊕ k. How can I change the encryption function E in order to make this cipher perfect(according to Shannon'

  • How would I go about starting to convert this code into OOP PHP? 2016-01-15

    I'm trying to learn about Object Oriented Programming and I want to turn this code into such. I've got some knowledge so far from google and here and in particular http://code.tutsplus.com/tutorials/object-oriented-php-for-beginners--net-12762. The w

  • How to insert an "index.php" into every url using .htaccess? 2009-12-21

    Example: My Site gets called like that: www.example.com/controller/method/parameter1/parameter2 Now, .htaccess needs to rewrite this URL into: www.example.com/index.php/controller/method/parameter1/parameter2 But the problem is: In case of an img, cs

  • Explain me, please, what "loop response" is, to help me translate this term into other language 2014-11-15

    English in not my native language. I've tried to find full definition of "loop response" in English, but I failed. Here is an example of using the term "loop response": As a working example of SIMPLIS time domain simulations, the Self

  • How to turn this HTML code into a shortcode? (adding song lyrics and giving an id to a div) 2011-03-19

    STEPS: Don't forget to use different id numbers in each accordion. For example: id="5" (1 to 10) The title goes between the The lyrics before the Place 2 accordions per posts (like the example below). Or they will mess up. <div class="ba

  • How to create shortcode of this PHP code 2014-02-24

    I tried a lot but failed to create shortcode of this PHP snippet: <ul> <?php $my_query = new WP_Query('post_status=future&order=DESC&showposts=10'); if ($my_query->have_posts()) { while ($my_query->have_posts()) : $my_query->the_

  • Adding php directly into widget shortcode 2015-03-20

    So here is my button shortcode in my widget. [button title="EDIT" href="<?php ech edit_product_url( $post->ID ); ?>"] As you can guess the href url does not work. What would be the best way to add php in the shortcode? Thanks

  • How to turn this into a routable network that works with pgRouting? 2013-12-22

    What I'm I doing wrong? I've created a new shape layer for lines, I've enabled snapping with 5 map units for that layer. When I draw a line between two of the stops I get a purple marker when I'm at the "right" spot, I click the first stop and t

  • Thoughts on turning this DropCap/Lettrine code into a macro 2014-06-26

    I am aware there are some packages available for Dropped Capitals, esp. the lettrine.sty package for LaTeX. However, I'm learning TeX from fundamentals and decided to figure out how to do it myself. I've written an implementation that works and is fl

  • Please help me turn this SQL query into SOQL query.. I'm stuck 2015-06-11

    I've been trying to figure out how to turn this SQL query into a SOQL query. Every time I think I am getting better with SOQL something comes along and erases that thought. Account is the parent object and has a Master-Detail relationship with Mercha

  • How do I Turn This Into An if statement? 2015-12-14

    PHP noob here. I've got this query I've written to get the information of all child pages of the page you're currently on: <?php $pages = get_pages('child_of=1015&sort_column=post_title'); $count = 0; foreach($pages as $page) { ?> <div class=

  • Turning Function into a shortcode - Wordpress 2016-01-14

    So I'm using this function below that works perfectly, however I want to convert it into a wordpress shortcode. <?php if( have_rows('pdf_download') ): while ( have_rows('pdf_download') ) : the_row(); ?> <ul> <li><a href="<?php

  • can anybody help me to covert this php code into laravel form 2016-03-01

    this is the php code for a cart .I need to convert this in to laravel form. it is somewhat difficult to pass the id and other thing.can anybody help me at this time <?php session_start(); //session_destroy(); include "connect.php"; $page='car

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 1.980 (s). 13 q(s)