• Hi there,

    I tried to find an answer for my question for over an hour, unfotunately with no results. Thats why I would be very happy if some of you guys have an answer for my question:

    I’m trying to set up nested shortcodes and found a lot for the “do shortcode”method.

    https://developer.wordpress.org/reference/functions/do_shortcode/

    Unfortunately I get no real results, maybe due to less php knowledge. The following code I want to implement:

    [embed][job_field key=”job_video”][/embed]

    The “[job_field key=”job_video”]” shortcode puts out a youtube URL. So the code would have to look like this: [embed]https://youtube.com?vsdf323r2[/embed]

    Does anybody know how I can get the code to work?

    Thanks a lot in advance!

    Julius

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hey there!

    I think the following tutorial can solve your problem. This tutorial uses do_shortcode() funtion to make nested shortcode in WordPress.

    http://www.sitepoint.com/wordpress-nested-shortcodes/

    Cheers!

    Assuming you have a list of keys and a list of urls to which they should translate, e.g., ‘job_video’ = ‘https://youtube.com?vsdf323r2’, ‘other_video’ = ‘https://youtube.com?abc123’, ‘another_video’ = ‘https://youtube.com?ca90210’, then you can write your own shortcode to do this for you.

    You can add this code directly to the end of your theme’s functions.php file (dangerous! Test this code first, back up your functions.php file before adding this code, and be ready to replace it via FTP if your code is bad!) or write it as a plugin (much safer).

    add_shortcode( 'job_field', 'job_field_shortcode_youtube_url' );
    
    function job_field_shortcode_youtube_url( $atts, $content = null ) {
    	switch( $atts['key'] ) {
    		case 'job_video':
    			return 'https://youtube.com?vsdf323r2';
    		case 'other_video':
    			return 'https://youtube.com?abc123';
    		case 'another_video':
    			return 'https://youtube.com?ca90210';
    		default:
    			return '';
    	}
    }

    Did I mention that you should back up your site before deploying this code, especially to the functions.php file? You totally should. Really, really.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘do shortcode problems with [embed]’ is closed to new replies.